package net.hn.hnms.biz.analysis.service.impl;

import com.alibaba.excel.util.ListUtils;
import lombok.extern.slf4j.Slf4j;
import net.hn.hnms.biz.analysis.config.AnalysisConfig;
import net.hn.hnms.biz.analysis.config.AnalysisConstant;
import net.hn.hnms.biz.analysis.domain.*;
import net.hn.hnms.biz.analysis.domain.dto.*;
import net.hn.hnms.biz.analysis.domain.enums.AlarmEnum;
import net.hn.hnms.biz.analysis.domain.vo.SensorMonitorVo;
import net.hn.hnms.biz.analysis.service.IDataJudgeService;
import net.hn.hnms.biz.analysis.service.IMineService;
import net.hn.hnms.biz.analysis.service.IProductionService;
import net.hn.hnms.biz.analysis.service.ISafetyService;
import net.hn.hnms.biz.analysis.utils.*;
import net.hn.hnms.sys.common.core.utils.DateUtils;
import net.hn.hnms.sys.common.core.utils.StringUtils;
import net.hn.hnms.sys.common.mybatis.config.MybatisMineCodeConfiguration;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @author: HN
 * @date: 2019/12/25 15:01
 * @version: 1.0
 * @description: 数据预警
 */
@Slf4j
@Service
public class DataJudgeServiceImpl implements IDataJudgeService {

    @Resource
    private MybatisMineCodeConfiguration.MineCode mybatisMineCodeConfig;

    @Resource
    private AnalysisConfig analysisConfig;

    @Resource
    private ISafetyService safetyService;

    @Resource
    private IMineService minerService;

    @Resource
    private IProductionService productionService;

    private final Random random = new Random();


    @Override
    public void MineJudgeScores() {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String lastBeginTime = lastDate + " 00:00:00";
        String lastEndTime = lastDate + " 23:59:59";
        String currentDate = DateUtils.parseDateToStr("yyyy-MM-dd", currentTime);
        String beginTime = currentDate + " 00:00:00";
        String endTime = currentDate + " 23:59:59";
        // 指标权重和数据
        List<SysIndicatorDto> sysIndicatorList = minerService.getSysIndicator();
        // 瓦斯相关指标值计算
        processGasDisaster(beginTime, endTime, sysIndicatorList);
        // 瓦斯评分计算
        mineGasJudge(sysIndicatorList.stream().filter(u -> StringUtils.equals(u.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS)).collect(Collectors.toList()), currentTime);

        //水害相关指标计算
        processWaterDisaster(lastBeginTime, lastEndTime, beginTime, endTime, sysIndicatorList);
        // 水害评分计算
        mineWaterJudge(sysIndicatorList.stream().filter(u -> StringUtils.equals(u.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER)).collect(Collectors.toList()), currentTime);

        //火灾评分计算
        mineFireJudge(sysIndicatorList.stream().filter(u -> StringUtils.equals(u.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE)).collect(Collectors.toList()), lastBeginTime, lastEndTime, currentTime);
        //粉尘评分计算
        dustFireJudge(sysIndicatorList.stream().filter(u -> StringUtils.equals(u.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST)).collect(Collectors.toList()), lastBeginTime, lastEndTime, currentTime);
        // 冲击地压评分计算
        groundPressureJudge(lastBeginTime, lastEndTime, currentTime);
    }

    @Override
    public void noLeader() {
        Date currentTime = DateUtils.getNowDate();
        // 获取当前日期时间
        LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
        // 如果需要转换为 Date 对象
        Date beginTime = Date.from(todayStart.atZone(ZoneId.systemDefault()).toInstant());
        String yesterday = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String beforeBegintime = yesterday + " 00:00:00";
        String beforeEndTime = yesterday + " 23:59:59";
        Date tempBeginTime = DateUtils.addHours(currentTime, -8);
        String bTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beginTime);
        if (tempBeginTime.after(beginTime)) {
            bTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, tempBeginTime);
        }
        String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentTime);
        //输出领导带班空岗数据
        List<OffDutyDto> offDutyList = safetyService.getOffDutyList(bTime, endTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(offDutyList)) {
            OffDutyDto yesterdayOffDuty = safetyService.getYesterdayWellOutTime(beforeBegintime, beforeEndTime, mybatisMineCodeConfig.getCode());
            Map<String, Object> dataResult = new HashMap<>();
            if (StringUtils.isNotNull(yesterdayOffDuty)) {
                dataResult = calculateLeaderOffDutyDuration(offDutyList, endTime, DateUtils.getDate(), yesterdayOffDuty);
            } else {
                dataResult = calculateOffDutyDurationWithoutYesterdayMaxTime(offDutyList, endTime, DateUtils.getDate());
            }
            List<OffDutyRecord> offDutyRecords = assembleData(DateUtils.parseDate(yesterday), dataResult);
            Boolean isExist = checkCurrentLeaderDuty(bTime, endTime);
            if (CollectionUtils.isNotEmpty(offDutyRecords) && !isExist) {
                safetyService.saveOffDutyRecord(offDutyRecords);
            }
        }
    }


    private Map<String, CoalfaceSensorPreditDto> processCoalfaceSensorData(CoalfaceSensorDto trainTuple, List<MiningFaceDto> miningFaceData) {
        Map<String, CoalfaceSensorPreditDto> resultMap = new HashMap<>();
        List<BaseStationInfoDto> baseStationInfoDtoList = safetyService.getSensorInfo(trainTuple.getCode(), trainTuple.getName());
        baseStationInfoDtoList.forEach(item -> {
            item.setSensorTypeName(AnalysisConstant.SENSOR_TYPE_DICT.get(item.getSensorType()));
        });
        Map<String, List<BaseStationInfoDto>> stringListMap = matchCoalFaceSensor(baseStationInfoDtoList, miningFaceData);
        for (Map.Entry<String, List<BaseStationInfoDto>> entry : stringListMap.entrySet()) {
            String key = entry.getKey();
            List<BaseStationInfoDto> value = entry.getValue();

            // 解析工作面参数
            String[] coalfaceParams = key.split("~");
            String coalfaceName = coalfaceParams[0];
            String coalfaceId = coalfaceParams[1];

            // 遍历传感器信息
            for (BaseStationInfoDto item : value) {
                String sensorCode = item.getPointCode();
                String sensorTypeItem = item.getSensorType();
                String sensorTypeName = item.getSensorTypeName();
                String sensorLocation = item.getPointMonitorLocation();

                item.setCoalfaceId(coalfaceId);
                item.setCoalfaceName(coalfaceName);
                // 构造参数数组

                // 构造数据键
                String dataKey = String.format("%s~%s~%s~%s~%s~%s", sensorCode, sensorTypeItem, sensorTypeName,
                        sensorLocation, coalfaceName, coalfaceId);

                // 获取传感器数据
                List<SensorDataDto> sensorData = safetyService.getSensorData(sensorCode, trainTuple.getBTime(), trainTuple.getETime());

                // 转换传感器数据
                List<Double> final_list = ListUtils.newArrayList();
                Map<String, Double> final_dict = new HashMap<>();
                convertSensorData(sensorData, trainTuple.getBTime(), trainTuple.getETime(), final_list, final_dict);

                // 批量插入传感器数据
                batchInsertSensorData(item, final_dict, 0);

                // 更新数据字典
                resultMap.put(dataKey, new CoalfaceSensorPreditDto(final_list, final_dict));
            }
        }
        return resultMap;
    }

    private void batchInsertSensorData(BaseStationInfoDto item, Map<String, Double> finalDict, int dataFlag) {
        List<SensorConvertedData> resultList = new ArrayList<>();
        finalDict.forEach((key, value) -> {
            SensorConvertedData sensorConvertedData = new SensorConvertedData(DateUtils.parseDate(key), "lstm", item.getCoalfaceId(), item.getPointCode(), item.getSensorType(), dataFlag, item.getPointMonitorLocation(), item.getSensorTypeName(), item.getCoalfaceName(), value);
            resultList.add(sensorConvertedData);
        });
        if (CollectionUtils.isNotEmpty(resultList)) {
            safetyService.batchInsertSensorData(resultList);
        }
    }

    private void convertSensorData(List<SensorDataDto> sensorData, String bTime, String eTime, List<Double> final_list, Map<String, Double> final_dict) {
        Date tempDate = DateUtils.parseDate(bTime);
        String oneMinuteTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(tempDate, 1));
        Map<String, String> oneMinuteDict = DataJudgeUtil.createTimeDict(bTime, eTime, oneMinuteTime, 1);
        // 初始化传感器字典
        Map<Date, Double> sensorDict = new HashMap<>();

        for (Map.Entry<String, String> entry : oneMinuteDict.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            Date fTime = DateUtils.parseDate(key);
            Date lTime = DateUtils.parseDate(value);
            List<SensorDataDto> tempList = new ArrayList<>();

            // 筛选在当前时间区间内的传感器数据
            for (SensorDataDto sensor : sensorData) {
                Date dataTime = sensor.getDataTime();
                if (!dataTime.before(fTime) && !dataTime.after(lTime)) {
                    tempList.add(sensor);
                }
            }

            // 如果有数据，取最大值；否则插值为 0
            if (!tempList.isEmpty()) {
                tempList.sort((s1, s2) -> Double.compare(s2.getPointValue(), s1.getPointValue()));
                SensorDataDto maxSensor = tempList.get(0);
                sensorDict.put(maxSensor.getDataTime(), maxSensor.getPointValue());
            } else {
                sensorDict.put(fTime, 0.0);
            }
        }

        for (Map.Entry<Date, Double> entry : sensorDict.entrySet()) {
            final_list.add(entry.getValue());
        }

        int count = 0;
        for (Map.Entry<Date, Double> entry : sensorDict.entrySet()) {
            if (count < sensorDict.size()) {
                double sensorValue = final_list.get(count);
                final_dict.put(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, entry.getKey()), sensorValue);
                count++;
            }
        }
    }

    public Map<String, List<BaseStationInfoDto>> matchCoalFaceSensor(List<BaseStationInfoDto> sensorList, List<MiningFaceDto> miningFaceData) {
        Map<String, List<BaseStationInfoDto>> dataDict = new HashMap<>();

        for (MiningFaceDto miningFaceDatum : miningFaceData) {
            String value = miningFaceDatum.getMiningFaceCode();
            String key = miningFaceDatum.getMiningFaceName();
            // 分词处理
            List<String> p = jiebaCut(key);
            List<BaseStationInfoDto> tempList = new ArrayList<>();
            for (BaseStationInfoDto item : sensorList) {
                String sensorLocation = item.getPointMonitorLocation();
                List<String> q = jiebaCut(sensorLocation);
                int count = 0;
                int specialCount = 0;
                // 统计匹配的词数
                for (String word : q) {
                    if (p.contains(word)) {
                        count++;
                    }
                    if (AnalysisConstant.WORD_DICT.stream().anyMatch(u -> u.contains(word))) {
                        specialCount++;
                    }
                }
                // 如果满足条件，加入临时列表
                if (count > 0 && specialCount > 0) {
                    tempList.add(item);
                }
            }
            // 构造数据键并存储到字典中
            String dataKey = String.format("%s~%s", key, value);
            dataDict.put(dataKey, tempList);
        }
        return dataDict;
    }


    @Override
    public void spontaneousCombustion() {
        Date currentTime = DateUtils.getNowDate();
        String beginTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addHours(currentTime, -1));
        String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentTime);
        List<MiningFaceDto> miningFaceData = minerService.getMiningFaceData();
        List<SensorMonitorDto> sensorAlarmData = safetyService.selectSensorAlarmData("0003", beginTime, endTime, "工作面");
        if (CollectionUtils.isNotEmpty(miningFaceData)) {
            List<CoalSpontaneousCombustionAlarm> coalSpontaneousCombustionAlarmList = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(sensorAlarmData)) {
                for (SensorMonitorDto sensorMonitorDto : sensorAlarmData) {
                    for (MiningFaceDto miningFaceDto : miningFaceData) {
                        String miningFaceName = miningFaceDto.getMiningFaceName();
                        // 分词处理
                        List<String> params = jiebaCut(miningFaceName);
                        int count = 0;
                        for (String param : params) {
                            if (sensorMonitorDto.getPointLocation().contains(param)) {
                                count++;
                            }
                        }
                        if (count == params.size()) {
                            float alarmType = FireRuleUtil.getCombustionAlarmDetailLevel(sensorMonitorDto.getPointMaxValue());
                            CoalSpontaneousCombustionAlarm coalSpontaneousCombustionAlarm = coalSpontaneousCombustionAlarmList.stream().filter(u -> StringUtils.equals(u.getMineCode(), mybatisMineCodeConfig.getCode()) && StringUtils.equals(u.getPointCode(), sensorMonitorDto.getPointCode())).findFirst().orElse(null);
                            if (coalSpontaneousCombustionAlarm == null) {
                                coalSpontaneousCombustionAlarm = new CoalSpontaneousCombustionAlarm(currentTime, sensorMonitorDto.getDataTime(), miningFaceDto.getMiningFaceCode(), sensorMonitorDto.getPointCode(), miningFaceDto.getMiningFaceName(), sensorMonitorDto.getPointLocation(), alarmType, null);
                                coalSpontaneousCombustionAlarmList.add(coalSpontaneousCombustionAlarm);
                            } else {
                                if (coalSpontaneousCombustionAlarm.getAlarmType() < alarmType) {
                                    coalSpontaneousCombustionAlarm.setAlarmType(alarmType);
                                    coalSpontaneousCombustionAlarm.setDataTime(sensorMonitorDto.getDataTime());
                                }
                            }
                        }
                    }
                }
            } else {
                for (MiningFaceDto miningFaceDto : miningFaceData) {
                    CoalSpontaneousCombustionAlarm coalSpontaneousCombustionAlarm = new CoalSpontaneousCombustionAlarm(currentTime, currentTime, mybatisMineCodeConfig.getCode(), miningFaceDto.getMiningFaceCode(), "", miningFaceDto.getMiningFaceName(), 1F, 100F);
                    coalSpontaneousCombustionAlarmList.add(coalSpontaneousCombustionAlarm);
                }
            }
            safetyService.insertCoalSpontaneousCombustionAlarm(coalSpontaneousCombustionAlarmList);
        }
    }

    @Override
    public void staffAnalysis() {
        //领导睡岗
        leaderSleepings();
        //空岗
        noLeader();
        //煤矿在不同时间点的超员次数 煤矿在不同地点的超员次数
        overStaff();
        //出井异常分析
        wellOut();
    }

    @Override
    public void roofAbscission() {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String lastBeginTime = lastDate + " 00:00:00";
        String lastEndTime = lastDate + " 23:59:59";
        // 顶板离层
        List<RoofAbscissionDto> roofAbscissionData = safetyService.getRoofAbscissionData(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(roofAbscissionData)) {
            roofAbscissionData.forEach(roofAbscissionDto -> roofAbscissionDto.setMineCode(mybatisMineCodeConfig.getCode()));
            minerService.batchInsertRoofAbscissionAlarm(roofAbscissionData);
        }
        // 支架阻力
        List<SupportPressureDto> supportPressureData = safetyService.getSupportPressureData(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(supportPressureData)) {
            supportPressureData.forEach(supportPressureDto -> supportPressureDto.setMineCode(mybatisMineCodeConfig.getCode()));
            minerService.batchInsertSupportdataAlarm(supportPressureData);
        }
    }

    @Override
    public void staffStatistics() {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String lastBeginTime = lastDate + " 00:00:00";
        String lastEndTime = lastDate + " 23:59:59";
        String sTime = lastDate + " 01:00:00";
        Map<String, String> timeDict = DataJudgeUtil.createTimeDict(lastBeginTime, lastEndTime, sTime, 60);
        Map<String, Integer> staffDict = new HashMap<>();
        Map<String, Integer> leaderDict = new HashMap<>();
        Map<String, Integer> specialStaffDict = new HashMap<>();
        Map<String, Integer> keyAreaDict = new HashMap<>();
        for (Map.Entry<String, String> entry : timeDict.entrySet()) {
            // 重点区域
            Integer count = safetyService.getKeyAreaStaffCount(entry.getKey(), entry.getValue(), mybatisMineCodeConfig.getCode());
            keyAreaDict.put(entry.getKey(), count != null ? count : 0);
            // 总人数
            Integer staffCount = safetyService.getStaffCount(entry.getKey(), entry.getValue(), mybatisMineCodeConfig.getCode());
            staffDict.put(entry.getKey(), staffCount != null ? staffCount : 0);
            // 特殊人员
            Integer specialStaffCount = safetyService.getSpecialStaffCount(entry.getKey(), entry.getValue(), mybatisMineCodeConfig.getCode());
            specialStaffDict.put(entry.getKey(), specialStaffCount != null ? specialStaffCount : 0);
            //领导
            Integer leaderCount = safetyService.getLeaderCount(entry.getKey(), entry.getValue(), mybatisMineCodeConfig.getCode());
            leaderDict.put(entry.getKey(), leaderCount != null ? leaderCount : 0);
        }
        // 1. 计算最大值和最小值 (staff)
        List<Map.Entry<String, Integer>> sortedStaff = staffDict.entrySet().stream()
                .sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
                .collect(Collectors.toList());
        int maxStaffCount = sortedStaff.get(0).getValue();
        int minStaffCount = sortedStaff.get(sortedStaff.size() - 1).getValue();

        // 2. 计算最大值 (leader)
        List<Map.Entry<String, Integer>> sortedLeader = leaderDict.entrySet().stream()
                .sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
                .collect(Collectors.toList());
        int maxLeaderCount = sortedLeader.get(0).getValue();

        // 3. 计算最大值 (special staff)
        List<Map.Entry<String, Integer>> sortedSpecialStaff = specialStaffDict.entrySet().stream()
                .sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
                .collect(Collectors.toList());
        int maxSpecialStaffCount = sortedSpecialStaff.get(0).getValue();

        // 4. 计算总人数和平均值 (staff)
        int staffTotalCount = staffDict.values().stream().mapToInt(Integer::intValue).sum();
        double staffAvg = Math.round((double) staffTotalCount / staffDict.size());

        // 5. 计算最大值 (key area)
        List<Map.Entry<String, Integer>> sortedKeyArea = keyAreaDict.entrySet().stream()
                .sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
                .collect(Collectors.toList());
        int maxKeyAreaStaffCount = sortedKeyArea.get(0).getValue();

        // 6. 获取基准人数并计算百分比
        int baseStaffCount = analysisConfig.getStaff().get("base_staff_count").intValue();
        double staffPercent = Math.round(((double) maxStaffCount / baseStaffCount) * 100);
        // 7. 构造结果列表
        HisMineStaffDayDto hisMineStaffDayDto = new HisMineStaffDayDto(mybatisMineCodeConfig.getCode(), currentTime, maxStaffCount, maxLeaderCount, maxSpecialStaffCount, maxKeyAreaStaffCount, minStaffCount, currentTime, staffAvg, staffPercent);
        // 8. 批量插入数据
        minerService.batchInsertStaff(Collections.singletonList(hisMineStaffDayDto));
    }

    @Override
    public void waterEmissionAlarm() {
        Date currentTime = DateUtils.getNowDate();
        String b_time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(currentTime, -15));
        String e_time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, currentTime);
        String before_same_b_time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(currentTime, -1455));
        String before_same_e_time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(currentTime, -1440));
        List<WaterEmissionAlarmDto> waterEmissionAlarmData = safetyService.getWaterInflowData(b_time, e_time, mybatisMineCodeConfig.getCode());
        List<WaterEmissionAlarmDto> beforeWaterEmissionAlarmData = safetyService.getWaterInflowData(before_same_b_time, before_same_e_time, mybatisMineCodeConfig.getCode());
        Map<String, WaterExtrmeDto> currentDict = waterEmissionAlarmData(waterEmissionAlarmData);
        Map<String, WaterExtrmeDto> beforeDict = waterEmissionAlarmData(beforeWaterEmissionAlarmData);
        List<WaterEmissionAlarmDay> waterEmissionAlarmDayList = new ArrayList<>();
        for (Map.Entry<String, WaterExtrmeDto> entry : currentDict.entrySet()) {
            String key = entry.getKey();
            WaterExtrmeDto value = entry.getValue();

            // 提取字段
            String pointCode = value.getPointCode();
            String sensorType = value.getSensorType();
            String sensorLocation = value.getSensorLocation();
            float maxWaterDischarge = value.getMaxWaterDischarge();
            Date maxWaterDischargeTime = value.getMaxWaterDischargeTime();

            // 如果当前点存在于历史字典中
            if (beforeDict.containsKey(key)) {
                WaterExtrmeDto beforeSensor = beforeDict.get(key);
                double waterDischarge = beforeSensor.getMaxWaterDischarge();
                Date waterDischargeTime = beforeSensor.getMaxWaterDischargeTime();

                // 计算增长率
                double increaseRate = round((maxWaterDischarge - waterDischarge) / maxWaterDischarge, 2);

                // 获取报警类型
                String alarmType = DataJudgeUtil.getAlarmType(increaseRate);

                WaterEmissionAlarmDay waterEmissionAlarmDay = new WaterEmissionAlarmDay(DateUtils.parseDate(b_time), DateUtils.parseDate(e_time), mybatisMineCodeConfig.getCode(), pointCode, sensorType, sensorLocation, alarmType, waterDischargeTime, maxWaterDischargeTime, waterDischarge, maxWaterDischarge);
                // 添加到数据列表
                waterEmissionAlarmDayList.add(waterEmissionAlarmDay);
            }
        }
        // 如果数据列表不为空，批量插入
        if (CollectionUtils.isNotEmpty(waterEmissionAlarmDayList)) {
            minerService.batchInsertWaterEmissionAlarm(waterEmissionAlarmDayList);
        }
    }

    @Override
    public void miningDriving() {
        //重大设备开机率传感器统计
        miningStart();
    }

    @Override
    public void equipStop() {
        //重大设备停机率传感器统计
        Map<String, String> equipmentStart = analysisConfig.getEquipmentStart();
        getStopData(equipmentStart.get("mining"), 0);
        getStopData(equipmentStart.get("mining"), 0);
        getStopData(equipmentStart.get("driving"), 1);
        getStopData(equipmentStart.get("belt_transport"), 2);
        getStopData(equipmentStart.get("inclined_shaft"), 3);
        getStopData(equipmentStart.get("main_fan"), 4);
        getStopData(equipmentStart.get("pressure_fan"), 5);
        getStopData(equipmentStart.get("main_drainage"), 6);
        getStopData(equipmentStart.get("gas_drainage"), 7);
        getStopData(equipmentStart.get("nitrogen"), 8);
    }

    @Override
    public void equipStart() {
        miningStart();
    }

    @Override
    public void equipInterrupted() {
        Map<String, String> equipmentStart = analysisConfig.getEquipmentStart();
        getDataInterruptedData(equipmentStart.get("mining"), 0);
    }

    private void getDataInterruptedData(String sensorInfo, int equipmentFlag) {
        String equipmentName = AnalysisConstant.EQUIPMENT_TYPE.get(equipmentFlag);
        if (StringUtils.isBlank(sensorInfo)) {
            log.info("重大设备传感器中断统计，未配置{}传感器编号", equipmentName);
        } else {
            List<List<SensorStatusDto>> sensorInfos = DataJudgeUtil.createSensorInfos(sensorInfo);
            List<EquipmentSensorAttributeDto> sensorList = new ArrayList<>();
            List<MajorEquipmentStartDay> interruptedList = new ArrayList<>();
            for (List<SensorStatusDto> sensorInfoList : sensorInfos) {
                for (SensorStatusDto sensorStatusDto : sensorInfoList) {
                    getInterruptedData(sensorStatusDto, equipmentFlag, interruptedList, sensorList);
                }
            }
            if (CollectionUtils.isNotEmpty(sensorList)) {
                sensorList.sort(Comparator.comparing(EquipmentSensorAttributeDto::getBTime));
                List<EquipmentStartDetailsDay> detailsList = combineIntersectionSensorData(sensorList, 2);
                if (CollectionUtils.isNotEmpty(detailsList)) {
                    productionService.batchInsertDiffSensorValue(detailsList);
                }
            }
            if (CollectionUtils.isNotEmpty(interruptedList)) {
                productionService.batchInsertSensorValue(interruptedList);
            }
        }
    }

    private void getInterruptedData(SensorStatusDto point, int equipmentFlag, List<MajorEquipmentStartDay> interruptedList, List<EquipmentSensorAttributeDto> sensorList) {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String bTime = lastDate + " 00:00:00";
        String eTime = lastDate + " 23:59:59";
        String pointCode = point.getSensorTag();
        String tableName = point.getTableName();
        String deviceCategory = point.getDeviceCategory();
        String deviceSequenceNumber = point.getDeviceSequenceNumber();
        String deviceName = point.getDeviceName();
        String md5Key = point.getMd5Key();
        List<EquipValueDto> equipValueDtoList = null;
        if (equipmentFlag == 2 || equipmentFlag == 4 || equipmentFlag == 6 || equipmentFlag == 8 || equipmentFlag == 5) {
            equipValueDtoList = productionService.getStartupRateData(tableName, bTime, eTime, pointCode, mybatisMineCodeConfig.getCode());
        } else {
            equipValueDtoList = productionService.getStartupRateOtherData(tableName, bTime, eTime, pointCode, mybatisMineCodeConfig.getCode());
        }
        if (CollectionUtils.isNotEmpty(equipValueDtoList)) {
            for (int i = 0; i < equipValueDtoList.size(); i++) {
                EquipValueDto sensor = equipValueDtoList.get(i);
                Date dataTime = sensor.getDataTime();

                for (int j = 0; j < equipValueDtoList.size(); j++) {
                    if (j > i && j - i == 1) {
                        EquipValueDto tempSensor = equipValueDtoList.get(j);
                        Date dataTimeAfter = tempSensor.getDataTime();
                        String pointValueUnit = tempSensor.getValueUnit();

                        long seconds = Duration.between(dataTime.toInstant(), dataTimeAfter.toInstant()).getSeconds();
                        double duration = Math.round((seconds / 60.0) * 10000.0) / 10000.0;

                        if (duration > 0) {
                            String bTimeStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dataTime);
                            String eTimeStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dataTimeAfter);

                            String stringKey = String.format("%s~%s~%s~%s~%s~%s",
                                    pointCode, deviceCategory, deviceSequenceNumber, deviceName, bTimeStr, eTimeStr);

                            String hashCode = DataJudgeUtil.generateMd5Hashcode(stringKey);
                            MajorEquipmentStartDay temp = new MajorEquipmentStartDay(hashCode, mybatisMineCodeConfig.getCode(), currentTime, pointCode, deviceCategory, deviceSequenceNumber, dataTime, dataTimeAfter, pointValueUnit, duration, equipmentFlag, deviceName, md5Key, 2);
                            Optional<MajorEquipmentStartDay> first = interruptedList.stream().filter(item -> !item.getHashCode().equals(hashCode)).findFirst();
                            if (!first.isPresent()) {
                                EquipmentSensorAttributeDto equip = new EquipmentSensorAttributeDto();
                                equip.setBTime(dataTime);
                                equip.setETime(dataTimeAfter);
                                equip.setMd5Key(md5Key);
                                equip.setSensorCode(pointCode);
                                equip.setEquipmentFlag(equipmentFlag);
                                sensorList.add(equip);
                                interruptedList.add(temp);
                            }
                        }
                    }
                }
            }
        }
    }

    private void getStopData(String sensorInfo, int equipmentFlag) {
        String equipmentName = AnalysisConstant.EQUIPMENT_TYPE.get(equipmentFlag);
        if (StringUtils.isBlank(sensorInfo)) {
            log.info("重大设备停机率传感器统计，未配置{}传感器编号", equipmentName);
        } else {
            List<List<SensorStatusDto>> sensorInfos = DataJudgeUtil.createSensorInfos(sensorInfo);
            List<EquipmentSensorAttributeDto> sensorList = new ArrayList<>();
            List<MajorEquipmentStartDay> dataList = new ArrayList<>();
            for (List<SensorStatusDto> sensorInfoList : sensorInfos) {
                for (SensorStatusDto sensorStatusDto : sensorInfoList) {
                    getStopRateData(sensorStatusDto, equipmentFlag, dataList, sensorList);
                }
            }
            if (CollectionUtils.isNotEmpty(sensorList)) {
                sensorList.sort(Comparator.comparing(EquipmentSensorAttributeDto::getBTime));
                List<EquipmentStartDetailsDay> detailsList = combineIntersectionSensorData(sensorList, 1);
                if (CollectionUtils.isNotEmpty(detailsList)) {
                    productionService.batchInsertDiffSensorValue(detailsList);
                }
            }
            if (CollectionUtils.isNotEmpty(dataList)) {
                productionService.batchInsertSensorValue(dataList);
            }
        }
    }

    private List<EquipmentStartDetailsDay> combineIntersectionSensorData(List<EquipmentSensorAttributeDto> dataList, int dataFlag) {
        Date currentTime = DateUtils.getNowDate();
        Date beginTime = null;
        Date endTime = null;
        List<EquipmentStartDetailsDay> result = new ArrayList<>();
        Set<String> firstSet = new HashSet<>();

        if (!dataList.isEmpty()) {
            for (int i = 0; i < dataList.size(); i++) {
                EquipmentSensorAttributeDto sensor = dataList.get(i);
                Date bTime = sensor.getBTime();
                Date eTime = sensor.getETime();
                String sensorCode = sensor.getSensorCode();
                int equipmentFlag = sensor.getEquipmentFlag();
                String md5Key = sensor.getMd5Key();

                for (int j = 0; j < dataList.size(); j++) {
                    if (j > i) {
                        EquipmentSensorAttributeDto tempSensor = dataList.get(j);
                        String tempSensorCode = tempSensor.getSensorCode();
                        Date tempFTime = tempSensor.getBTime();
                        Date tempSTime = tempSensor.getETime();
                        firstSet.add(sensorCode);
                        firstSet.add(tempSensorCode);
                        if (beginTime == null && endTime == null) {
                            if (bTime.before(tempFTime) || bTime.equals(tempFTime)) {
                                if (eTime.before(tempSTime) || eTime.equals(tempSTime)) {
                                    beginTime = tempFTime;
                                    endTime = eTime;
                                } else {
                                    beginTime = tempFTime;
                                    endTime = tempSTime;
                                }
                            } else if (eTime.before(tempFTime)) {
                                beginTime = eTime;
                                endTime = tempFTime;
                            }
                            firstSet.add(sensorCode);
                            firstSet.add(tempSensorCode);
                        } else {
                            if (beginTime.before(tempFTime) && endTime.after(tempSTime)) {
                                firstSet.add(sensorCode);
                                firstSet.add(tempSensorCode);
                                beginTime = tempFTime;
                                endTime = tempSTime;
                            } else if (beginTime.before(tempFTime) && endTime.before(tempSTime)) {
                                firstSet.add(sensorCode);
                                firstSet.add(tempSensorCode);
                                beginTime = tempFTime;
                                // endTime remains unchanged
                            }

                            String tempSensors = String.join(",", firstSet);
                            String stringKey1 = String.format("%s~%s~%s~%s", tempSensors, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beginTime),
                                    DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime), equipmentFlag);
                            String hashCode1 = DataJudgeUtil.generateMd5Hashcode(stringKey1);

                            long seconds1 = Duration.between(beginTime.toInstant(), endTime.toInstant()).getSeconds();
                            double duration1 = Math.round((seconds1 / 60.0) * 10000.0) / 10000.0;

                            EquipmentStartDetailsDay temp1 = new EquipmentStartDetailsDay(hashCode1, mybatisMineCodeConfig.getCode(), currentTime, tempSensors, beginTime, tempFTime, duration1, equipmentFlag, md5Key, dataFlag);
                            Optional<EquipmentStartDetailsDay> first = result.stream().filter(u -> u.getHashCode().equals(hashCode1)).findFirst();
                            if (!first.isPresent()) {
                                result.add(temp1);
                            }
                            firstSet.clear();
                            firstSet.add(tempSensorCode);
                        }
                        break;
                    }
                }
            }
        }
        return result;
    }

    private void getStopRateData(SensorStatusDto point, int equipmentFlag, List<MajorEquipmentStartDay> dataList, List<EquipmentSensorAttributeDto> sensorList) {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String bTime = lastDate + " 00:00:00";
        String eTime = lastDate + " 23:59:59";
        String pointCode = point.getSensorTag();
        String tableName = point.getTableName();
        String deviceCategory = point.getDeviceCategory();
        String deviceSequenceNumber = point.getDeviceSequenceNumber();
        String deviceName = point.getDeviceName();
        String md5Key = point.getMd5Key();
        List<EquipValueDto> equipValueDtoList = null;
        if (equipmentFlag == 2 || equipmentFlag == 4 || equipmentFlag == 6 || equipmentFlag == 8 || equipmentFlag == 5) {
            equipValueDtoList = productionService.getStartupRateData(tableName, bTime, eTime, pointCode, mybatisMineCodeConfig.getCode());
        } else {
            equipValueDtoList = productionService.getStartupRateOtherData(tableName, bTime, eTime, pointCode, mybatisMineCodeConfig.getCode());
        }
        if (CollectionUtils.isNotEmpty(equipValueDtoList)) {
            Date startBTime = null;
            Date startETime = null;
            Date specialBTime = null;
            Date specialETime = null;
            String pointValueUnit = null;

            for (EquipValueDto item : equipValueDtoList) {
                Date dataTime = item.getDataTime();
                pointValueUnit = item.getValueUnit();
                int pointStatus = Integer.parseInt(item.getPointValue());

                if (startBTime == null) {
                    if (pointStatus == point.getStopFlag()) {
                        startBTime = dataTime;
                        if (specialBTime == null) {
                            specialBTime = dataTime;
                        }
                    }
                } else {
                    if (pointStatus == point.getStartFlag()) {
                        startETime = dataTime;
                    }
                }

                if (startBTime != null && startETime != null) {
                    long seconds = Duration.between(startBTime.toInstant(), startETime.toInstant()).getSeconds();
                    double duration = Math.round((seconds / 60.0) * 10000.0) / 10000.0;

                    if (duration != 0) {
                        String bTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", startBTime);
                        String eTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", startETime);
                        String stringKey = String.format("%s~%s~%s~%s~%s~%s", pointCode, deviceCategory,
                                deviceSequenceNumber, deviceName, bTimeStr, eTimeStr);
                        String hashCode = DataJudgeUtil.generateMd5Hashcode(stringKey);
                        MajorEquipmentStartDay temp = new MajorEquipmentStartDay(hashCode, mybatisMineCodeConfig.getCode(), currentTime, pointCode, deviceCategory, deviceSequenceNumber, startBTime, startETime, pointValueUnit, duration, equipmentFlag, deviceName, md5Key, 1);
                        Optional<MajorEquipmentStartDay> first = dataList.stream().filter(t -> t.getHashCode().equals(hashCode)).findFirst();
                        if (!first.isPresent()) {
                            dataList.add(temp);
                            EquipmentSensorAttributeDto equip = new EquipmentSensorAttributeDto();
                            equip.setBTime(startBTime);
                            equip.setETime(startETime);
                            equip.setMd5Key(md5Key);
                            equip.setSensorCode(pointCode);
                            equip.setEquipmentFlag(equipmentFlag);
                            sensorList.add(equip);
                        }
                    }

                    startBTime = null;
                    startETime = null;
                } else {
                    if (specialBTime != null && specialETime == null) {
                        specialETime = dataTime;
                    }
                }
            }

            // 处理剩余的特殊时间段
            if (specialBTime != null) {
                long seconds = Duration.between(specialBTime.toInstant(), specialETime.toInstant()).getSeconds();
                double duration = Math.round((seconds / 60.0) * 10000.0) / 10000.0;

                if (duration != 0) {
                    String bTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", specialBTime);
                    String eTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", specialETime);
                    String stringKey = String.format("%s~%s~%s~%s~%s~%s", pointCode, deviceCategory,
                            deviceSequenceNumber, deviceName, bTimeStr, eTimeStr);
                    String hashCode = DataJudgeUtil.generateMd5Hashcode(stringKey);
                    MajorEquipmentStartDay temp = new MajorEquipmentStartDay(hashCode, mybatisMineCodeConfig.getCode(), currentTime, pointCode, deviceCategory, deviceSequenceNumber, specialBTime, specialETime, pointValueUnit, duration, equipmentFlag, deviceName, md5Key, 1);
                    Optional<MajorEquipmentStartDay> first = dataList.stream().filter(t -> t.getHashCode().equals(hashCode)).findFirst();
                    if (!first.isPresent()) {
                        EquipmentSensorAttributeDto equip = new EquipmentSensorAttributeDto();
                        equip.setBTime(specialBTime);
                        equip.setETime(specialETime);
                        equip.setMd5Key(md5Key);
                        equip.setSensorCode(pointCode);
                        equip.setEquipmentFlag(equipmentFlag);
                        sensorList.add(equip);
                        dataList.add(temp);
                    }
                }
            }
        }
    }

    private void miningStart() {
        Map<String, String> equipmentStart = analysisConfig.getEquipmentStart();
        getStartupData(equipmentStart.get("mining"), 0);
        getStartupData(equipmentStart.get("driving"), 1);
        getStartupData(equipmentStart.get("belt_transport"), 2);
        getStartupData(equipmentStart.get("inclined_shaft"), 3);
        getStartupData(equipmentStart.get("main_fan"), 4);
        getStartupData(equipmentStart.get("pressure_fan"), 5);
        getStartupData(equipmentStart.get("main_drainage"), 6);
        getStartupData(equipmentStart.get("gas_drainage"), 7);
        getStartupData(equipmentStart.get("nitrogen"), 8);
    }

    private void getStartupData(String sensorInfo, int equipmentFlag) {
        String equipmentName = AnalysisConstant.EQUIPMENT_TYPE.get(equipmentFlag);
        if (StringUtils.isBlank(sensorInfo)) {
            log.info("重大设备开机率传感器统计，未配置{}传感器编号", equipmentName);
        } else {
            List<List<SensorStatusDto>> sensorInfos = DataJudgeUtil.createSensorInfos(sensorInfo);
            List<EquipmentSensorAttributeDto> sensorList = new ArrayList<>();
            List<MajorEquipmentStartDay> dataList = new ArrayList<>();
            for (List<SensorStatusDto> item : sensorInfos) {
                for (SensorStatusDto point : item) {
                    getStartupRateData(point, equipmentFlag, dataList, sensorList);
                }
            }
            if (CollectionUtils.isNotEmpty(sensorList)) {
                sensorList.sort(Comparator.comparing(EquipmentSensorAttributeDto::getBTime));
                List<EquipmentStartDetailsDay> list = combineDifferentSensorData(sensorList);
                if (CollectionUtils.isNotEmpty(list)) {
                    productionService.batchInsertDiffSensorValue(list);
                }
            }
            if (CollectionUtils.isNotEmpty(dataList)) {
                productionService.batchInsertSensorValue(dataList);
            }
        }
    }

    public List<EquipmentStartDetailsDay> combineDifferentSensorData(List<EquipmentSensorAttributeDto> dataList) {
        List<EquipmentStartDetailsDay> result = new ArrayList<>();
        Date currentTime = DateUtils.getNowDate();
        Date beginTime = null;
        Date endTime = null;
        Set<String> firstSet = new HashSet<>();

        if (!dataList.isEmpty()) {
            for (int i = 0; i < dataList.size(); i++) {
                EquipmentSensorAttributeDto sensor = dataList.get(i);
                Date bTime = sensor.getBTime();
                Date eTime = sensor.getETime();
                String sensorCode = sensor.getSensorCode();
                int equipmentFlag = sensor.getEquipmentFlag();
                String md5Key = sensor.getMd5Key();

                for (int j = 0; j < dataList.size(); j++) {
                    if (j > i) {
                        EquipmentSensorAttributeDto tempSensor = dataList.get(j);
                        String tempSensorCode = tempSensor.getSensorCode();
                        Date tempFTime = tempSensor.getBTime();
                        Date tempSTime = tempSensor.getETime();

                        firstSet.add(sensorCode);
                        firstSet.add(tempSensorCode);

                        if (beginTime == null && endTime == null) {
                            if (bTime.before(tempFTime) || bTime.equals(tempFTime)) {
                                if (eTime.before(tempSTime) || eTime.equals(tempSTime)) {
                                    beginTime = bTime;
                                    endTime = tempSTime;
                                } else if (eTime.after(tempSTime)) {
                                    beginTime = bTime;
                                    endTime = eTime;
                                }
                            } else if (eTime.before(tempFTime)) {
                                beginTime = tempFTime;
                                endTime = tempSTime;
                            }
                            firstSet.add(sensorCode);
                            firstSet.add(tempSensorCode);
                        } else {
                            if (beginTime.before(tempFTime) && endTime.after(tempSTime)) {
                                firstSet.add(sensorCode);
                                firstSet.add(tempSensorCode);
                            } else if (beginTime.before(tempFTime) && endTime.before(tempSTime)) {
                                endTime = tempSTime;
                                firstSet.add(sensorCode);
                                firstSet.add(tempSensorCode);
                            } else if (tempFTime.after(endTime)) {
                                String tempSensors = String.join(",", firstSet);
                                String stringKey1 = String.format("%s~%s~%s~%s", tempSensors, beginTime, endTime, equipmentFlag);
                                String hashCode1 = DataJudgeUtil.generateMd5Hashcode(stringKey1);
                                long seconds1 = Duration.between(beginTime.toInstant(), endTime.toInstant()).getSeconds();
                                double duration1 = Math.round((seconds1 / 60.0) * 10000.0) / 10000.0;
                                EquipmentStartDetailsDay temp1 = new EquipmentStartDetailsDay(hashCode1, mybatisMineCodeConfig.getCode(), currentTime, tempSensors, beginTime, endTime, duration1, equipmentFlag, md5Key, 0);
                                Optional<EquipmentStartDetailsDay> first = result.stream().filter(o -> o.getHashCode().equals(hashCode1)).findFirst();
                                if (!first.isPresent()) {
                                    result.add(temp1);
                                }
                                beginTime = tempFTime;
                                endTime = tempSTime;
                                firstSet.clear();
                                firstSet.add(tempSensorCode);
                                continue;
                            }
                        }
                        break;
                    }
                }
            }
        }
        return result;
    }

    public void getStartupRateData(SensorStatusDto point, int equipmentFlag, List<MajorEquipmentStartDay> dataList, List<EquipmentSensorAttributeDto> sensorList) {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String bTime = lastDate + " 00:00:00";
        String eTime = lastDate + " 23:59:59";
        String pointCode = point.getSensorTag();
        String tableName = point.getTableName();
        String deviceCategory = point.getDeviceCategory();
        String deviceSequenceNumber = point.getDeviceSequenceNumber();
        String deviceName = point.getDeviceName();
        String md5Key = point.getMd5Key();
        List<EquipValueDto> equipValueDtoList = null;
        if (equipmentFlag == 2 || equipmentFlag == 4 || equipmentFlag == 6 || equipmentFlag == 8 || equipmentFlag == 5) {
            equipValueDtoList = productionService.getStartupRateData(tableName, bTime, eTime, pointCode, mybatisMineCodeConfig.getCode());
        } else {
            equipValueDtoList = productionService.getStartupRateOtherData(tableName, bTime, eTime, pointCode, mybatisMineCodeConfig.getCode());
        }

        if (CollectionUtils.isNotEmpty(equipValueDtoList)) {
            Date startBTime = null;
            Date startETime = null;
            Date specialBTime = null;
            Date specialETime = null;
            String pointValueUnit = null;

            for (EquipValueDto item : equipValueDtoList) {
                Date dataTime = item.getDataTime();
                pointValueUnit = item.getValueUnit();
                int pointStatus = Integer.parseInt(item.getPointValue());

                if (startBTime == null) {
                    if (pointStatus == point.getStartFlag() || pointStatus > 0) {
                        startBTime = dataTime;
                        if (specialBTime == null) {
                            specialBTime = dataTime;
                        }
                    }
                } else {
                    if (pointStatus == point.getStopFlag()) {
                        startETime = dataTime;
                    }
                }

                if (startBTime != null && startETime != null) {
                    long seconds = Duration.between(startBTime.toInstant(), startETime.toInstant()).getSeconds();
                    double duration = Math.round(seconds / 60.0 * 10000.0) / 10000.0;

                    if (duration != 0) {
                        String bTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", startBTime);
                        String eTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", startETime);
                        String stringKey = String.format("%s~%s~%s~%s~%s~%s", pointCode, deviceCategory, deviceSequenceNumber,
                                deviceName, bTimeStr, eTimeStr);
                        String hashCode = DataJudgeUtil.generateMd5Hashcode(stringKey);
                        Optional<MajorEquipmentStartDay> first = dataList.stream().filter(d -> d.getHashCode().equals(hashCode)).findFirst();
                        if (!first.isPresent()) {
                            MajorEquipmentStartDay temp = new MajorEquipmentStartDay(hashCode, mybatisMineCodeConfig.getCode(), currentTime, pointCode, deviceCategory, deviceSequenceNumber, startBTime, startETime, pointValueUnit, duration, equipmentFlag, deviceName, md5Key, null);
                            dataList.add(temp);
                            EquipmentSensorAttributeDto equip = new EquipmentSensorAttributeDto();
                            equip.setBTime(startBTime);
                            equip.setETime(startETime);
                            equip.setMd5Key(md5Key);
                            equip.setSensorCode(pointCode);
                            equip.setEquipmentFlag(equipmentFlag);
                            sensorList.add(equip);
                        }
                    }
                    startBTime = null;
                    startETime = null;
                } else {
                    if (specialBTime != null && specialETime == null) {
                        specialETime = dataTime;
                    }
                }
            }

            if (specialBTime != null) {
                long seconds = Duration.between(specialBTime.toInstant(), specialETime.toInstant()).getSeconds();
                double duration = Math.round(seconds / 60.0 * 10000.0) / 10000.0;

                if (duration != 0) {
                    String bTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", specialBTime);
                    String eTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", specialETime);
                    String stringKey = String.format("%s~%s~%s~%s~%s~%s", pointCode, deviceCategory, deviceSequenceNumber,
                            deviceName, bTimeStr, eTimeStr);
                    String hashCode = DataJudgeUtil.generateMd5Hashcode(stringKey);
                    Optional<MajorEquipmentStartDay> first = dataList.stream().filter(d -> d.getHashCode().equals(hashCode)).findFirst();
                    if (!first.isPresent()) {
                        MajorEquipmentStartDay temp = new MajorEquipmentStartDay(hashCode, mybatisMineCodeConfig.getCode(), currentTime, pointCode, deviceCategory, deviceSequenceNumber, specialBTime, specialETime, pointValueUnit, duration, equipmentFlag, deviceName, md5Key, null);
                        EquipmentSensorAttributeDto equip = new EquipmentSensorAttributeDto();
                        equip.setBTime(specialBTime);
                        equip.setETime(specialETime);
                        equip.setMd5Key(md5Key);
                        equip.setSensorCode(pointCode);
                        equip.setEquipmentFlag(equipmentFlag);
                        sensorList.add(equip);
                        dataList.add(temp);
                    }
                }
            }
        }
    }

    private double round(double value, int places) {
        double scale = Math.pow(10, places);
        return Math.round(value * scale) / scale;
    }

    private Map<String, WaterExtrmeDto> waterEmissionAlarmData(List<WaterEmissionAlarmDto> waterEmissionAlarmData) {
        Map<String, WaterExtrmeDto> pointDict = new HashMap<>();
        if (CollectionUtils.isNotEmpty(waterEmissionAlarmData)) {
            for (WaterEmissionAlarmDto item : waterEmissionAlarmData) {
                // 如果单位在单位列表中，乘以 60
                if (AnalysisConstant.WATER_UNIT_LIST.contains(item.getPointUnit())) {
                    item.setPointValue(item.getPointValue() * 60);
                }

                // 如果点代码不在字典中，创建新对象
                if (!pointDict.containsKey(item.getPointCode())) {
                    WaterExtrmeDto water = new WaterExtrmeDto();
                    water.setMineCode(item.getMineCode());
                    water.setPointCode(item.getPointCode());
                    water.setPointStatus(item.getPointStatus());
                    water.setSensorType(item.getSensorType());
                    water.setSensorLocation(item.getSensorLocation());
                    water.setMaxWaterDischarge(item.getPointValue());
                    water.setMaxWaterDischargeTime(item.getDataTime());
                    water.setTotalWaterDischarge(item.getPointValue());
                    pointDict.put(item.getPointCode(), water);
                } else {
                    // 如果点代码已存在，更新最大值
                    WaterExtrmeDto water = pointDict.get(item.getPointCode());
                    Float maxWaterDischarge = water.getMaxWaterDischarge();
                    if (item.getPointValue() > maxWaterDischarge) {
                        water.setMaxWaterDischarge(item.getPointValue());
                        water.setMaxWaterDischargeTime(item.getDataTime());
                    }
                }
            }
        }
        return pointDict;
    }

    private void wellOut() {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String lastBeginTime = lastDate + " 00:00:00";
        String lastEndTime = lastDate + " 23:59:59";
        List<WellOutDto> wellOutData = safetyService.getWellOutData(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(wellOutData)) {
            wellOutData.forEach(wellOutDto -> wellOutDto.setCreateTime(currentTime));
            minerService.saveHisWellOutTimeStatistics(wellOutData);
        }
    }

    private void overStaff() {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String lastBeginTime = lastDate + " 00:00:00";
        String lastEndTime = lastDate + " 23:59:59";
        List<BaseOverManAlarm> baseOverManAlarms = safetyService.getOverManAlarm(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(baseOverManAlarms)) {
            // 区域超员
            List<MineAreaOverStaffTimeDay> mineAreaOverStaffTimeDayList = new ArrayList<>();
            List<BaseOverManAlarm> areaOverManAlarms = baseOverManAlarms.stream().filter(u -> StringUtils.equals(u.getAlarmType(), "区域超员")).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(areaOverManAlarms)) {
                for (BaseOverManAlarm baseOverManAlarm : areaOverManAlarms) {
                    MineAreaOverStaffTimeDay mineAreaOverStaffTimeDay = mineAreaOverStaffTimeDayList.stream().filter(u -> StringUtils.equals(u.getMineCode(), baseOverManAlarm.getMineCode()) && StringUtils.equals(u.getAreaCode(), baseOverManAlarm.getAreaCode())).findFirst().orElse(null);
                    if (mineAreaOverStaffTimeDay == null) {
                        mineAreaOverStaffTimeDay = new MineAreaOverStaffTimeDay(currentTime, baseOverManAlarm.getMineCode(), baseOverManAlarm.getAreaCode(), baseOverManAlarm.getAreaName());
                        mineAreaOverStaffTimeDayList.add(mineAreaOverStaffTimeDay);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 00:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 02:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount1(mineAreaOverStaffTimeDay.getMineCount1() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 02:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 04:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount2(mineAreaOverStaffTimeDay.getMineCount2() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 04:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 06:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount3(mineAreaOverStaffTimeDay.getMineCount3() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 06:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 08:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount4(mineAreaOverStaffTimeDay.getMineCount4() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 08:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 10:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount5(mineAreaOverStaffTimeDay.getMineCount5() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 10:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 12:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount6(mineAreaOverStaffTimeDay.getMineCount6() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 12:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 14:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount7(mineAreaOverStaffTimeDay.getMineCount7() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 14:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 16:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount8(mineAreaOverStaffTimeDay.getMineCount8() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 16:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 18:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount9(mineAreaOverStaffTimeDay.getMineCount9() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 18:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 20:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount10(mineAreaOverStaffTimeDay.getMineCount10() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 20:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 22:00:00"))) {
                        mineAreaOverStaffTimeDay.setMineCount11(mineAreaOverStaffTimeDay.getMineCount11() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 22:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 23:59:59"))) {
                        mineAreaOverStaffTimeDay.setMineCount12(mineAreaOverStaffTimeDay.getMineCount12() + 1);
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(mineAreaOverStaffTimeDayList)) {
                minerService.saveMineAreaOverStaffTimeDay(mineAreaOverStaffTimeDayList);
            }
            //矿井超员
            List<BaseOverManAlarm> overManAlarms = baseOverManAlarms.stream().filter(u -> StringUtils.equals(u.getAlarmType(), "矿井超员")).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(overManAlarms)) {
                MineOverStaffTimeDay mineOverStaffTimeDay = new MineOverStaffTimeDay(currentTime, mybatisMineCodeConfig.getCode());
                for (BaseOverManAlarm baseOverManAlarm : overManAlarms) {
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 00:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 02:00:00"))) {
                        mineOverStaffTimeDay.setMineCount1(mineOverStaffTimeDay.getMineCount1() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 02:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 04:00:00"))) {
                        mineOverStaffTimeDay.setMineCount2(mineOverStaffTimeDay.getMineCount2() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 04:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 06:00:00"))) {
                        mineOverStaffTimeDay.setMineCount3(mineOverStaffTimeDay.getMineCount3() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 06:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 08:00:00"))) {
                        mineOverStaffTimeDay.setMineCount4(mineOverStaffTimeDay.getMineCount4() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 08:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 10:00:00"))) {
                        mineOverStaffTimeDay.setMineCount5(mineOverStaffTimeDay.getMineCount5() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 10:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 12:00:00"))) {
                        mineOverStaffTimeDay.setMineCount6(mineOverStaffTimeDay.getMineCount6() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 12:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 14:00:00"))) {
                        mineOverStaffTimeDay.setMineCount7(mineOverStaffTimeDay.getMineCount7() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 14:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 16:00:00"))) {
                        mineOverStaffTimeDay.setMineCount8(mineOverStaffTimeDay.getMineCount8() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 16:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 18:00:00"))) {
                        mineOverStaffTimeDay.setMineCount9(mineOverStaffTimeDay.getMineCount9() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 18:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 20:00:00"))) {
                        mineOverStaffTimeDay.setMineCount10(mineOverStaffTimeDay.getMineCount10() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 20:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 22:00:00"))) {
                        mineOverStaffTimeDay.setMineCount11(mineOverStaffTimeDay.getMineCount11() + 1);
                    }
                    if (baseOverManAlarm.getAlarmStartTime().after(DateUtils.parseDate(lastDate + " 22:00:00")) && baseOverManAlarm.getAlarmStartTime().before(DateUtils.parseDate(lastDate + " 23:59:59"))) {
                        mineOverStaffTimeDay.setMineCount12(mineOverStaffTimeDay.getMineCount12() + 1);
                    }
                }
                minerService.saveMineOverStaffTimeDay(Collections.singletonList(mineOverStaffTimeDay));
            }
        }
    }

    private void leaderSleepings() {
        Date currentTime = DateUtils.getNowDate();
        String lastDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(currentTime, -1));
        String lastBeginTime = lastDate + " 00:00:00";
        String lastEndTime = lastDate + " 23:59:59";
        //领导在同一区域超过14400000毫秒就疑似睡岗
        List<OffDutyDto> mineDuty = safetyService.getLeaderAttendencyByTime(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(mineDuty)) {
            List<LeaderExceptionJudgeDay> leaderExceptionJudgeDays = new ArrayList<>();
            Map<String, List<OffDutyDto>> collect = mineDuty.stream().collect(Collectors.groupingBy(u -> String.format("%s~%s~%s", u.getStaffCode(), u.getStaffName(), DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", u.getWellTime()))));
            for (Map.Entry<String, List<OffDutyDto>> entry : collect.entrySet()) {
                List<OffDutyDto> offDutyDtos = entry.getValue();
                offDutyDtos.sort(Comparator.comparing(OffDutyDto::getAreaInTime));
                for (int i = 1; i < offDutyDtos.size(); i++) {
                    long time = offDutyDtos.get(i - 1).getAreaInTime().getTime() - offDutyDtos.get(i).getAreaInTime().getTime();
                    if (time > 14400000) {
                        LeaderExceptionJudgeDay leaderExceptionJudgeDay = new LeaderExceptionJudgeDay(mybatisMineCodeConfig.getCode(), DateUtils.parseDate(lastDate), offDutyDtos.get(i - 1).getStaffCode(), offDutyDtos.get(i - 1).getWellTime(), offDutyDtos.get(i - 1).getAreaInTime(), offDutyDtos.get(i).getAreaInTime(), offDutyDtos.get(i).getStaffName());
                        leaderExceptionJudgeDays.add(leaderExceptionJudgeDay);
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(leaderExceptionJudgeDays)) {
                minerService.saveLeaderException(leaderExceptionJudgeDays);
            }
        }
    }

    /**
     * 模拟分词工具（jieba.lcut）
     */
    private List<String> jiebaCut(String key) {
        return Arrays.asList(key.split(""));
    }


    private Boolean checkCurrentLeaderDuty(String beginTime, String endTime) {
        boolean isExist = false;
        List<OffDutyDto> offDutyList = safetyService.getCurrentLeaderDuty(beginTime, endTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(offDutyList)) {
            isExist = true;
        }
        return isExist;
    }

    /**
     * 组装领导带班空岗数据
     *
     * @param currentTime     当前时间
     * @param offDutyDuration 包含空岗时间段及总时长的 Map
     * @return 组装好的空岗数据列表
     */
    public List<OffDutyRecord> assembleData(Date currentTime, Map<String, Object> offDutyDuration) {
        List<OffDutyRecord> offDuties = new ArrayList<>();

        // 遍历空岗时间段
        for (Map.Entry<String, Object> entry : offDutyDuration.entrySet()) {
            String timeKey = entry.getKey();
            Object value = entry.getValue();

            // 跳过总时长键 'duration' 和总时长为 0 的情况
            if (!timeKey.equals("duration") && !offDutyDuration.get("duration").equals(0)) {
                // 解析时间段信息
                String[] timeSpan = timeKey.split(",");
                Date beginTime = DateUtils.parseDate(timeSpan[4]);
                Date endTime = DateUtils.parseDate(timeSpan[5]);

                // 提取其他字段
                String staffCodeBefore = timeSpan[0].isEmpty() ? "" : timeSpan[0];
                String staffNameBefore = timeSpan[1].isEmpty() ? "" : timeSpan[1];
                String staffCodeCurrent = timeSpan[2].isEmpty() ? "" : timeSpan[2];
                String staffNameCurrent = timeSpan[3].isEmpty() ? "" : timeSpan[3];

                // 创建实体对象
                OffDutyRecord record = new OffDutyRecord(currentTime, beginTime, endTime, staffCodeBefore, staffNameBefore, staffCodeCurrent, staffNameCurrent, (Long) value);
                // 添加到结果列表
                offDuties.add(record);
            }
        }
        return offDuties;
    }

    /**
     * 计算每个矿的领导带班空岗的起始时间与空岗时间间隔
     *
     * @param mineDuty    当前矿的值班记录列表
     * @param currentDate 当前日期时间
     * @param beforeDate  前一个日期时间
     * @param beforeDuty  前一个值班记录
     * @return 包含空岗时间和详细信息的 Map
     */
    public static Map<String, Object> calculateLeaderOffDutyDuration(List<OffDutyDto> mineDuty, String currentDate, String beforeDate, OffDutyDto beforeDuty) {

        long duration = 0; // 空岗总时间（秒）
        Map<String, Object> dataResult = new HashMap<>();
        Date beginTime = DateUtils.parseDate(beforeDate);
        Date endTime = DateUtils.parseDate(currentDate);

        int length = mineDuty.size();
        if (length == 0) {
            return dataResult;
        }

        // 获取第一条和最后一条记录的相关信息
        OffDutyDto firstRecord = mineDuty.get(0);
        OffDutyDto lastRecord = mineDuty.get(length - 1);

        Date firstTime = firstRecord.getWellTime();
        Date firstTimeEnd = firstRecord.getWellOutTime();
        String firstStaffCode = firstRecord.getStaffCode();
        String firstStaffName = firstRecord.getStaffName();

        Date lastTime = lastRecord.getWellOutTime();
        Date lastTimeIn = lastRecord.getWellTime();
        String lastStaffCode = lastRecord.getStaffCode();
        String lastStaffName = lastRecord.getStaffName();

        String beforeStaffCode = beforeDuty.getStaffCode();
        String beforeStaffName = beforeDuty.getStaffName();
        Date beforeMaxTime = beforeDuty.getWellOutTime();

        // 处理第一个时间段的空岗时间
        if (beforeMaxTime.after(beginTime) && beforeMaxTime.before(firstTime)) {
            long intervals = Duration.between(beforeDuty.getWellOutTime().toInstant(), firstTime.toInstant()).getSeconds();
            duration += intervals;
            String keyTime = String.format("%s,%s,%s,%s,%s,%s", beforeStaffCode, beforeStaffName, firstStaffCode, firstStaffName, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beforeDuty.getWellOutTime()), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, firstRecord.getWellTime()));
            dataResult.put(keyTime, intervals);
            firstTime = firstTimeEnd;
        } else if (beforeMaxTime.after(firstTime) && beforeMaxTime.after(firstTimeEnd)) {
            firstTime = beforeMaxTime;
        } else if (beforeMaxTime.before(beginTime) && firstTime.after(beginTime)) {
            long timeIntervals = Duration.between(beginTime.toInstant(), firstTime.toInstant()).getSeconds();
            duration += timeIntervals;
            String keyTime = String.format("%s,%s,%s,%s,%s,%s", beforeStaffCode, beforeStaffName, firstStaffCode, firstStaffName, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beginTime), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, firstRecord.getWellTime()));
            dataResult.put(keyTime, timeIntervals);
            firstTime = firstTimeEnd;
        }

        // 处理最后一个时间段的空岗时间
        if (lastTime.before(endTime)) {
            long timeInterval = Duration.between(lastTime.toInstant(), endTime.toInstant()).getSeconds();
            duration += timeInterval;
            String keyTime = String.format("%s,%s,%s,%s,%s,%s", lastStaffCode, lastStaffName, "", "", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, lastRecord.getWellOutTime()), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime));
            dataResult.put(keyTime, timeInterval);
            firstTime = lastTime;
        } else {
            firstTime = lastTimeIn;
        }

        // 遍历中间的时间段
        for (int i = 1; i < length - 1; i++) {
            OffDutyDto record = mineDuty.get(i);
            Date enterTime = record.getWellTime();
            Date outTime = record.getWellOutTime();
            String enterStaffCode = record.getStaffCode();
            String enterStaffName = record.getStaffName();

            if (enterTime.before(firstTime) && outTime.before(firstTime)) {
                continue;
            }
            if (enterTime.before(firstTime) && outTime.after(firstTime)) {
                firstTime = outTime;
                continue;
            } else if (enterTime.after(firstTime) && outTime.after(firstTime)) {
                long timeLen = Duration.between(firstTime.toInstant(), enterTime.toInstant()).getSeconds();
                duration += timeLen;
                firstTime = outTime;
                String keyTime = String.format("%s,%s,%s,%s,%s,%s", beforeStaffCode, beforeStaffName, enterStaffCode, enterStaffName, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, enterTime), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, firstTime));
                beforeStaffCode = enterStaffCode;
                beforeStaffName = enterStaffName;
                dataResult.put(keyTime, timeLen);
            }
        }
        // 将总空岗时间存入结果
        dataResult.put("duration", duration);
        return dataResult;
    }

    /**
     * 计算无昨天最大出井时间的前提下的每个矿的领导带班空岗起始时间与空岗时间间隔
     *
     * @param mineDuty    当前矿的值班记录列表
     * @param currentDate 当前日期时间
     * @param beforeDate  前一个日期时间
     * @return 包含空岗时间和详细信息的 Map
     */
    public static Map<String, Object> calculateOffDutyDurationWithoutYesterdayMaxTime(List<OffDutyDto> mineDuty, String currentDate, String beforeDate) {

        long duration = 0; // 总空岗时长（秒）
        Map<String, Object> dataResult = new HashMap<>();

        // 时间范围
        Date beginTime = DateUtils.parseDate(beforeDate);
        Date endTime = DateUtils.parseDate(currentDate);

        // 第一条记录的关键信息
        OffDutyDto firstRecord = mineDuty.get(0);
        Date firstTime = firstRecord.getWellTime();
        String firstStaffCode = firstRecord.getStaffCode();
        String firstStaffName = firstRecord.getStaffName();

        // 遍历所有值班记录
        for (int i = 0; i < mineDuty.size(); i++) {
            OffDutyDto record = mineDuty.get(i);
            Date enterTime = record.getWellTime();
            Date outTime = record.getWellOutTime();
            String staffCode = record.getStaffCode();
            String staffName = record.getStaffName();

            if (i == 0) {
                // 处理第一条记录
                if (enterTime.after(beginTime)) {
                    long intervals = Duration.between(beginTime.toInstant(), enterTime.toInstant()).getSeconds();
                    duration += intervals;
                    firstTime = outTime;

                    String bTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beginTime);
                    String eTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, enterTime);
                    String keyTime = String.format("%s,%s,%s,%s,%s,%s", "", "", firstStaffCode, firstStaffName, bTime, eTime);

                    dataResult.put(keyTime, intervals);
                }
            } else {
                // 处理后续记录
                if (firstTime.after(enterTime) && firstTime.after(outTime)) {
                    continue;
                }
                if (firstTime.after(enterTime) && firstTime.before(outTime)) {
                    firstTime = outTime;
                    continue;
                }
                if (firstTime.before(enterTime)) {
                    long timeInterval = Duration.between(firstTime.toInstant(), enterTime.toInstant()).getSeconds();
                    duration += timeInterval;
                    firstTime = outTime;

                    String bTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, firstTime);
                    String eTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, enterTime);
                    String keyTime = String.format("%s,%s,%s,%s,%s,%s", firstStaffCode, firstStaffName, staffCode, staffName, bTime, eTime);

                    firstStaffCode = staffCode;
                    firstStaffName = staffName;
                    dataResult.put(keyTime, timeInterval);
                }
            }
        }

        // 处理最后一个时间段的空岗时间
        if (firstTime.before(endTime)) {
            long timeInterval = Duration.between(firstTime.toInstant(), endTime.toInstant()).getSeconds();
            duration += timeInterval;

            String bTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, firstTime);
            String eTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTime);
            String keyTime = String.format("%s,%s,%s,%s,%s,%s", firstStaffCode, firstStaffName, "", "", bTime, eTime);

            dataResult.put(keyTime, timeInterval);
        }
        // 将总空岗时间存入结果
        dataResult.put("duration", duration);
        return dataResult;
    }


    private void groundPressureJudge(String lastBeginTime, String lastEndTime, Date currentTime) {
        List<GroundPressureDto> groundPressureData = safetyService.getGroundPressureData(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(groundPressureData)) {
            groundPressureData.sort(Comparator.comparing(GroundPressureDto::getKri).reversed());
            GroundPressureDto groundPressureDto = groundPressureData.get(0);
            float groundPressureDisasterLevelScores = GroundPressureRuleUtil.getGroundPressureDisasterLevelScores(groundPressureDto.getKri());
            MineGroundPressureJudgement mineGroundPressureJudgement = new MineGroundPressureJudgement();
            mineGroundPressureJudgement.setMineCode(mybatisMineCodeConfig.getCode()).setDataDate(currentTime).setSensorCode(groundPressureDto.getFace()).setSensorLocation(groundPressureDto.getName()).setDataTime(currentTime).setSensorKri(groundPressureDto.getKri()).setSensorScores(groundPressureDisasterLevelScores);
            minerService.insertGroundPressureScores(mineGroundPressureJudgement);
        }
    }

    private void dustFireJudge(List<SysIndicatorDto> sysIndicatorList, String lastBeginTime, String lastEndTime, Date currentTime) {
        List<SysMineIndicatorModel> dustJudgeModelList = Lists.newArrayList();
        //staff score
        float staffDurationScores = 0.0f;
        float staffCountScores = 0.0f;
        //staff_duration_scores
        SysIndicatorDto staffDurationDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_STAFF_DURATION)).findFirst().orElse(null);
        if (staffDurationDto != null) {
            AlarmInfoDto minKeyGasInfo = getUndergroundDustExpousreDurationPersonCount(lastBeginTime, lastEndTime);
            float dustDurationScores = DustRuleUtil.getUndergroundDustExposureTime(minKeyGasInfo.getValue());
            staffDurationScores = dustDurationScores * staffDurationDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), staffDurationDto.getCreateTime(), currentTime, staffDurationDto.getIndicatorFirstLevelCode(), staffDurationDto.getIndicatorSecondLevelCode(), staffDurationDto.getIndicatorThirdLevelCode(), staffDurationScores, String.valueOf(dustDurationScores), minKeyGasInfo.getMsg()));
        }
        //staff_count_scores
        SysIndicatorDto staffCountDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_STAFF_COUNT)).findFirst().orElse(null);
        if (staffCountDto != null) {
            AlarmInfoDto minKeyGasInfo = getUndergroundDustExpousrePersonCount(lastBeginTime, lastEndTime);
            float dustCountScores = DustRuleUtil.getUndergroundDustExposurePersonCount(minKeyGasInfo.getValue());
            staffCountScores = dustCountScores * staffCountDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), staffCountDto.getCreateTime(), currentTime, staffCountDto.getIndicatorFirstLevelCode(), staffCountDto.getIndicatorSecondLevelCode(), staffCountDto.getIndicatorThirdLevelCode(), staffCountScores, String.valueOf(dustCountScores), minKeyGasInfo.getMsg()));
        }
        //dust_staff
        SysIndicatorDto dustStaffDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_STAFF) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (dustStaffDto != null) {
            float dustStaffScores = staffDurationScores + staffCountScores;
            float finalDustStaff = dustStaffScores * dustStaffDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustStaffDto.getCreateTime(), currentTime, dustStaffDto.getIndicatorFirstLevelCode(), dustStaffDto.getIndicatorSecondLevelCode(), dustStaffDto.getIndicatorThirdLevelCode(), finalDustStaff, String.valueOf(dustStaffScores), ""));
        }


        //enviorment scores
        float dustExplosionScores = 0.0f;
        float dustAlarmScores = 0.0f;
        float coalfaceWindspeedScores = 0.0f;
        //dust_explosion_scores
        SysIndicatorDto dustExplosionDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.COAL_DUST_EXPLOSION)).findFirst().orElse(null);
        if (dustExplosionDto != null) {
            String indicatorValue = dustExplosionDto.getIndicatorValue();
            String msg = StringUtils.equals(indicatorValue, "1") ? AnalysisConstant.DisasterMessage.NO_DUST_EXPLOSION_MESSAGE : AnalysisConstant.DisasterMessage.DUST_EXPLOSION_MESSAGE;
            float oriDustExplosionScores = DustRuleUtil.getCoalDustExplosionStatus(Float.parseFloat(indicatorValue));
            dustExplosionScores = oriDustExplosionScores * dustExplosionDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustExplosionDto.getCreateTime(), currentTime, dustExplosionDto.getIndicatorFirstLevelCode(), dustExplosionDto.getIndicatorSecondLevelCode(), dustExplosionDto.getIndicatorThirdLevelCode(), dustExplosionScores, String.valueOf(oriDustExplosionScores), msg));
        }
        //dust_alarm_scores
        SysIndicatorDto dustAlarmDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.COAL_DUST_ALARM_COUNT)).findFirst().orElse(null);
        if (dustAlarmDto != null) {
            String indicatorValue = "0";
            float oriDustAlarmScores = DustRuleUtil.getCoalDustAlarmCount(Float.parseFloat(indicatorValue));
            dustAlarmScores = oriDustAlarmScores * dustAlarmDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustAlarmDto.getCreateTime(), currentTime, dustAlarmDto.getIndicatorFirstLevelCode(), dustAlarmDto.getIndicatorSecondLevelCode(), dustAlarmDto.getIndicatorThirdLevelCode(), dustAlarmScores, String.valueOf(oriDustAlarmScores), "煤尘报警次数为0次"));
        }
        //coalface_windspeed_scores
        SysIndicatorDto coalfaceWindspeedDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.COALFACE_WINDSPEED)).findFirst().orElse(null);
        if (coalfaceWindspeedDto != null) {
            AlarmInfoDto minKeyGasInfo = getCoalfaceWindspeedMaxValue(lastBeginTime, lastEndTime);
            float oriCoalfaceWindspeedScores = DustRuleUtil.getCoalfaceWindspeed(minKeyGasInfo.getValue());
            coalfaceWindspeedScores = oriCoalfaceWindspeedScores * coalfaceWindspeedDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalfaceWindspeedDto.getCreateTime(), currentTime, coalfaceWindspeedDto.getIndicatorFirstLevelCode(), coalfaceWindspeedDto.getIndicatorSecondLevelCode(), coalfaceWindspeedDto.getIndicatorThirdLevelCode(), coalfaceWindspeedScores, String.valueOf(oriCoalfaceWindspeedScores), minKeyGasInfo.getMsg()));
        }
        //dust_enviorment
        SysIndicatorDto dustEnviormentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_ENVIRONMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (dustEnviormentDto != null) {
            float dustEnviormentScores = dustExplosionScores + dustAlarmScores + coalfaceWindspeedScores;
            float finalDustEnviorment = dustEnviormentScores * dustEnviormentDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustEnviormentDto.getCreateTime(), currentTime, dustEnviormentDto.getIndicatorFirstLevelCode(), dustEnviormentDto.getIndicatorSecondLevelCode(), dustEnviormentDto.getIndicatorThirdLevelCode(), finalDustEnviorment, String.valueOf(dustEnviormentScores), ""));
        }

        //equipment scores
        float dustRemovalEquipmentScores = 0.0f;
        float measuringPointsCoverageScores = 0.0f;
        float miningOperationMechanizedDegreeScores = 0.0f;
        float protectiveEquipmentScores = 0.0f;
        float dustMonitorSystemScores = 0.0f;
        //dust_removal_equipment_scores
        SysIndicatorDto dustRemovalEquipmentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_REMOVAL_EQUIPMENT_PERCENT)).findFirst().orElse(null);
        if (dustRemovalEquipmentDto != null) {
            String indicatorValue = dustRemovalEquipmentDto.getIndicatorValue();
            float oriDustRemovalEquipmentScores = DustRuleUtil.getDustRemovalEquipmentPercent(Float.parseFloat(indicatorValue));
            dustRemovalEquipmentScores = oriDustRemovalEquipmentScores * dustRemovalEquipmentDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustRemovalEquipmentDto.getCreateTime(), currentTime, dustRemovalEquipmentDto.getIndicatorFirstLevelCode(), dustRemovalEquipmentDto.getIndicatorSecondLevelCode(), dustRemovalEquipmentDto.getIndicatorThirdLevelCode(), dustRemovalEquipmentScores, String.valueOf(oriDustRemovalEquipmentScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //measuring_points_coverage_scores
        SysIndicatorDto measuringPointsCoverageDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.MEASURING_POINTS_COVERAGE)).findFirst().orElse(null);
        if (measuringPointsCoverageDto != null) {
            String indicatorValue = measuringPointsCoverageDto.getIndicatorValue();
            float oriMeasuringPointsCoverageScores = DustRuleUtil.getMeasuringPointsCoverage(Float.parseFloat(indicatorValue));
            measuringPointsCoverageScores = oriMeasuringPointsCoverageScores * measuringPointsCoverageDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), measuringPointsCoverageDto.getCreateTime(), currentTime, measuringPointsCoverageDto.getIndicatorFirstLevelCode(), measuringPointsCoverageDto.getIndicatorSecondLevelCode(), measuringPointsCoverageDto.getIndicatorThirdLevelCode(), measuringPointsCoverageScores, String.valueOf(oriMeasuringPointsCoverageScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //mining_operation_mechanized_degree_scores
        SysIndicatorDto miningOperationMechanizedDegreeDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.MINING_OPERATION_MECHANIZED_DEGREE)).findFirst().orElse(null);
        if (miningOperationMechanizedDegreeDto != null) {
            String indicatorValue = miningOperationMechanizedDegreeDto.getIndicatorValue();
            float oriMiningOperationMechanizedDegreeScores = DustRuleUtil.getMiningOperationMechanizedDegree(Float.parseFloat(indicatorValue));
            miningOperationMechanizedDegreeScores = oriMiningOperationMechanizedDegreeScores * miningOperationMechanizedDegreeDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), miningOperationMechanizedDegreeDto.getCreateTime(), currentTime, miningOperationMechanizedDegreeDto.getIndicatorFirstLevelCode(), miningOperationMechanizedDegreeDto.getIndicatorSecondLevelCode(), miningOperationMechanizedDegreeDto.getIndicatorThirdLevelCode(), miningOperationMechanizedDegreeScores, String.valueOf(oriMiningOperationMechanizedDegreeScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //protective_equipment_scores
        SysIndicatorDto protectiveEquipmentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.PROTECTIVE_EQUIPMENT_PERCENT)).findFirst().orElse(null);
        if (protectiveEquipmentDto != null) {
            String indicatorValue = protectiveEquipmentDto.getIndicatorValue();
            float oriProtectiveEquipmentScores = DustRuleUtil.getProtectiveEquipmentPercent(Float.parseFloat(indicatorValue));
            protectiveEquipmentScores = oriProtectiveEquipmentScores * protectiveEquipmentDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), protectiveEquipmentDto.getCreateTime(), currentTime, protectiveEquipmentDto.getIndicatorFirstLevelCode(), protectiveEquipmentDto.getIndicatorSecondLevelCode(), protectiveEquipmentDto.getIndicatorThirdLevelCode(), protectiveEquipmentScores, String.valueOf(oriProtectiveEquipmentScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //dust_monitor_system_scores
        SysIndicatorDto dustMonitorSystemDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_MONITOR_ONLINE_STATUS)).findFirst().orElse(null);
        if (dustMonitorSystemDto != null) {
            String indicatorValue = dustMonitorSystemDto.getIndicatorValue();
            float oriDustMonitorSystemScores = DustRuleUtil.getCoalDustAlarmCount(Float.parseFloat(indicatorValue));
            dustMonitorSystemScores = oriDustMonitorSystemScores * dustMonitorSystemDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustMonitorSystemDto.getCreateTime(), currentTime, dustMonitorSystemDto.getIndicatorFirstLevelCode(), dustMonitorSystemDto.getIndicatorSecondLevelCode(), dustMonitorSystemDto.getIndicatorThirdLevelCode(), dustMonitorSystemScores, String.valueOf(oriDustMonitorSystemScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //dust_equipment
        SysIndicatorDto dustEquipmentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_EQUIPMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (dustEquipmentDto != null) {
            float oriDustEquipment = dustRemovalEquipmentScores + measuringPointsCoverageScores + miningOperationMechanizedDegreeScores + protectiveEquipmentScores + dustMonitorSystemScores;
            float dustEquipmentScores = oriDustEquipment * dustEquipmentDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustEquipmentDto.getCreateTime(), currentTime, dustEquipmentDto.getIndicatorFirstLevelCode(), dustEquipmentDto.getIndicatorSecondLevelCode(), dustEquipmentDto.getIndicatorThirdLevelCode(), dustEquipmentScores, String.valueOf(oriDustEquipment), ""));
        }
        //management scores
        float dustPreventionSystemScores = 0.0f;
        float dustPreventionInsitutesScores = 0.0f;
        float personalProtectiveStatusScores = 0.0f;
        float dustEduStatusScores = 0.0f;
        float dustSuppressionImplementedScores = 0.0f;
        //dust_prevention_system_scores
        SysIndicatorDto dustPreventionSystemDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_PREVENTION_SYSTEM)).findFirst().orElse(null);
        if (dustPreventionSystemDto != null) {
            String indicatorValue = dustPreventionSystemDto.getIndicatorValue();
            float oriDustPreventionSystemScores = DustRuleUtil.getDustPreventionSystem(Integer.parseInt(indicatorValue));
            dustPreventionSystemScores = oriDustPreventionSystemScores * dustPreventionSystemDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustPreventionSystemDto.getCreateTime(), currentTime, dustPreventionSystemDto.getIndicatorFirstLevelCode(), dustPreventionSystemDto.getIndicatorSecondLevelCode(), dustPreventionSystemDto.getIndicatorThirdLevelCode(), dustPreventionSystemScores, String.valueOf(oriDustPreventionSystemScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //dust_prevention_insitutes_scores
        SysIndicatorDto dustPreventionInsitutesDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_PREVENTION_INSTITUTES)).findFirst().orElse(null);
        if (dustPreventionInsitutesDto != null) {
            String indicatorValue = dustPreventionInsitutesDto.getIndicatorValue();
            float oriDustPreventionInsitutesScores = DustRuleUtil.getDustPreventionInstitutes(Integer.parseInt(indicatorValue));
            dustPreventionInsitutesScores = oriDustPreventionInsitutesScores * dustPreventionInsitutesDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustPreventionInsitutesDto.getCreateTime(), currentTime, dustPreventionInsitutesDto.getIndicatorFirstLevelCode(), dustPreventionInsitutesDto.getIndicatorSecondLevelCode(), dustPreventionInsitutesDto.getIndicatorThirdLevelCode(), dustPreventionInsitutesScores, String.valueOf(oriDustPreventionInsitutesScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //personal_protective_status_scores
        SysIndicatorDto personalProtectiveStatusDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.PERSONAL_PROTECTIVE_STATUS)).findFirst().orElse(null);
        if (personalProtectiveStatusDto != null) {
            String indicatorValue = personalProtectiveStatusDto.getIndicatorValue();
            float oriPersonalProtectiveStatusScores = DustRuleUtil.getPersonalProtectiveStatus(Integer.parseInt(indicatorValue));
            personalProtectiveStatusScores = oriPersonalProtectiveStatusScores * personalProtectiveStatusDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), personalProtectiveStatusDto.getCreateTime(), currentTime, personalProtectiveStatusDto.getIndicatorFirstLevelCode(), personalProtectiveStatusDto.getIndicatorSecondLevelCode(), personalProtectiveStatusDto.getIndicatorThirdLevelCode(), personalProtectiveStatusScores, String.valueOf(oriPersonalProtectiveStatusScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //dust_edu_status_scores
        SysIndicatorDto dustEduStatusDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_EDUCATION_STATUS)).findFirst().orElse(null);
        if (dustEduStatusDto != null) {
            String indicatorValue = dustEduStatusDto.getIndicatorValue();
            float oriDustEduStatusScores = DustRuleUtil.getDustEducationStatus(Float.parseFloat(indicatorValue));
            dustEduStatusScores = oriDustEduStatusScores * dustEduStatusDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustEduStatusDto.getCreateTime(), currentTime, dustEduStatusDto.getIndicatorFirstLevelCode(), dustEduStatusDto.getIndicatorSecondLevelCode(), dustEduStatusDto.getIndicatorThirdLevelCode(), dustEduStatusScores, String.valueOf(oriDustEduStatusScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //dust_suppression_implemented_scores
        SysIndicatorDto dustSuppressionImplementedDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_SUPPRESSION_IMPLEMENTED)).findFirst().orElse(null);
        if (dustSuppressionImplementedDto != null) {
            String indicatorValue = dustSuppressionImplementedDto.getIndicatorValue();
            float oriDustSuppressionImplementedScores = DustRuleUtil.getDustSuppressionImplemented(Integer.parseInt(indicatorValue));
            dustSuppressionImplementedScores = oriDustSuppressionImplementedScores * dustSuppressionImplementedDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustSuppressionImplementedDto.getCreateTime(), currentTime, dustSuppressionImplementedDto.getIndicatorFirstLevelCode(), dustSuppressionImplementedDto.getIndicatorSecondLevelCode(), dustSuppressionImplementedDto.getIndicatorThirdLevelCode(), dustSuppressionImplementedScores, String.valueOf(oriDustSuppressionImplementedScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //dust_management
        SysIndicatorDto dustManagementDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.DustDisasterConstant.DUST) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.DustDisasterConstant.DUST_MANAGEMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (dustManagementDto != null) {
            float oriDustManagementScore = dustPreventionSystemScores + dustPreventionInsitutesScores + personalProtectiveStatusScores + dustEduStatusScores + dustSuppressionImplementedScores;
            float dustManagementScore = oriDustManagementScore * dustManagementDto.getIndicatorWeightValue();
            dustJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), dustManagementDto.getCreateTime(), currentTime, dustManagementDto.getIndicatorFirstLevelCode(), dustManagementDto.getIndicatorSecondLevelCode(), dustManagementDto.getIndicatorThirdLevelCode(), dustManagementScore, String.valueOf(oriDustManagementScore), ""));
        }
        if (CollectionUtils.isNotEmpty(dustJudgeModelList)) {
            minerService.batchInsertWeightScores(dustJudgeModelList);
        }
    }

    private AlarmInfoDto getCoalfaceWindspeedMaxValue(String lastBeginTime, String lastEndTime) {
        AlarmInfoDto alarmInfoDto = new AlarmInfoDto();
        List<AlarmInfoDto> coalfaceWindspeedMaxValue = safetyService.getCoalfaceWindspeedMaxValue(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(coalfaceWindspeedMaxValue)) {
            coalfaceWindspeedMaxValue.sort(Comparator.comparing(AlarmInfoDto::getValue).reversed());
            AlarmInfoDto alarmInfoDto1 = coalfaceWindspeedMaxValue.get(0);
            alarmInfoDto.setValue(alarmInfoDto1.getValue());
            alarmInfoDto.setMsg(String.format("%s 位置风速传感器，传感器数值为%s", alarmInfoDto1.getMsg(), alarmInfoDto1.getValue()));
        } else {
            alarmInfoDto.setValue(0);
            alarmInfoDto.setMsg("无风速传感器位置及数值数据");
        }
        return alarmInfoDto;
    }

    private AlarmInfoDto getUndergroundDustExpousrePersonCount(String lastBeginTime, String lastEndTime) {
        AlarmInfoDto dustInfo = new AlarmInfoDto();
        List<MiningFaceDto> miningFaceData = getMiningFaceData();
        List<String> coalfaceId = miningFaceData.stream().map(MiningFaceDto::getMiningFaceCode).collect(Collectors.toList());
        List<AreaStaffCountDto> dustPersonCount = safetyService.getDustExpousrePersonCount(coalfaceId, lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(dustPersonCount)) {
            dustPersonCount.sort(Comparator.comparing(AreaStaffCountDto::getStaffCount).reversed());
            dustInfo.setValue(dustPersonCount.get(0).getStaffCount());
            dustInfo.setMsg("本矿井下工作面单班作业最大人数" + dustPersonCount.get(0).getStaffCount() + "人,接尘作业人数较多");
        } else {
            dustInfo.setValue(0);
            dustInfo.setMsg("本矿井下工作面单班作业最大人数为0人");
        }
        return dustInfo;
    }

    private AlarmInfoDto getUndergroundDustExpousreDurationPersonCount(String lastBeginTime, String lastEndTime) {
        AlarmInfoDto dustInfo = new AlarmInfoDto();
        List<MiningFaceDto> miningFaceData = getMiningFaceData();
        List<String> coalfaceId = miningFaceData.stream().map(MiningFaceDto::getMiningFaceCode).collect(Collectors.toList());
        List<AreaStaffCountDto> dustExpousreDurationPersonCount = safetyService.getDustExpousreDurationPersonCount(coalfaceId, lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        if (CollectionUtils.isNotEmpty(dustExpousreDurationPersonCount)) {
            dustExpousreDurationPersonCount.sort(Comparator.comparing(AreaStaffCountDto::getStaffCount).reversed());
            dustInfo.setValue(dustExpousreDurationPersonCount.get(0).getStaffCount());
            dustInfo.setMsg("本矿井下超时" + dustExpousreDurationPersonCount.get(0).getStaffCount() + "人,接尘时间较长");
        } else {
            dustInfo.setValue(0);
            dustInfo.setMsg("本矿井下超时0人");
        }
        return dustInfo;
    }

    private List<MiningFaceDto> getMiningFaceData() {
        return minerService.getMiningFaceData();
    }

    private void mineFireJudge(List<SysIndicatorDto> sysIndicatorList, String lastBeginTime, String lastEndTime, Date currentTime) {
        List<SysMineIndicatorModel> fireJudgeModelList = Lists.newArrayList();
        float internalFireScores = 0.0f;
        float coalSpontaneousCombustionScores = 0.0f;
        String internalFireMessage = "";
        String coalSpontaneousCombustionTendencyMessage = "";
        //internalfire_scores
        SysIndicatorDto resistivityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.COALFACE_TEMPERATURE)).findFirst().orElse(null);
        if (resistivityDto != null) {
            float scores = 100.0f;
            AnalysisScoreDto internalFireScore = getInternalFireScores(lastBeginTime, lastEndTime);
            if (internalFireScore != null) {
                scores = internalFireScore.getScores();
                internalFireMessage = String.format("传感器编号：%s, 传感器位置：%s, 传感器温度：%s℃, 属于%s风险", internalFireScore.getPointCode(), internalFireScore.getPointLocation(), internalFireScore.getPointMaxValue(), internalFireScore.getAlarmLevel());
            }
            internalFireScores = scores * resistivityDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), resistivityDto.getCreateTime(), currentTime, resistivityDto.getIndicatorFirstLevelCode(), resistivityDto.getIndicatorSecondLevelCode(), resistivityDto.getIndicatorThirdLevelCode(), internalFireScores, String.valueOf(scores), internalFireMessage));
        }
        //coal_spontaneous_combustion_scores
        SysIndicatorDto coalSpontaneousCombustionDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.COAL_SPONTANEOUS_COMBUSTION_TENDENCY_LEVEL)).findFirst().orElse(null);
        if (coalSpontaneousCombustionDto != null) {
            String indicatorValue = coalSpontaneousCombustionDto.getIndicatorValue();
            coalSpontaneousCombustionTendencyMessage = FireRuleUtil.getCoalSpontaneousCombustionTendencyMessage(Integer.parseInt(indicatorValue));
            coalSpontaneousCombustionScores = Float.parseFloat(indicatorValue) * coalSpontaneousCombustionDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalSpontaneousCombustionDto.getCreateTime(), currentTime, coalSpontaneousCombustionDto.getIndicatorFirstLevelCode(), coalSpontaneousCombustionDto.getIndicatorSecondLevelCode(), coalSpontaneousCombustionDto.getIndicatorThirdLevelCode(), coalSpontaneousCombustionScores, indicatorValue, coalSpontaneousCombustionTendencyMessage));
        }
        //internal_fire_score
        SysIndicatorDto internalFireScoreDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.FireDisasterConstant.INTERNAL_FIRE_RISK_LEVEL) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (internalFireScoreDto != null) {
            float internalFireScore = internalFireScores + coalSpontaneousCombustionScores;
            float scores = internalFireScore * internalFireScoreDto.getIndicatorWeightValue();
            String fireMessage = internalFireMessage + '\n' + coalSpontaneousCombustionTendencyMessage;
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), internalFireScoreDto.getCreateTime(), currentTime, internalFireScoreDto.getIndicatorFirstLevelCode(), internalFireScoreDto.getIndicatorSecondLevelCode(), internalFireScoreDto.getIndicatorThirdLevelCode(), scores, String.valueOf(internalFireScore), fireMessage));
        }
        // TODO 以下报警全是模拟值
        float smokeScores = 0.0f;
        float temperatureScores = 0.0f;
        float keyGasScores = 0.0f;
        String smokeMessage = "";
        String temperatureMessage = "";
        String keyGasMessage = "";
        //smoke_scores
        SysIndicatorDto smokeDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.SMOKE_MONITOR_EARLY_WARNING)).findFirst().orElse(null);
        if (smokeDto != null) {
            AlarmInfoDto minSmokeInfo = getMinSmokeInfo();
            float minSmoke = minSmokeInfo.getValue();
            smokeScores = minSmoke * smokeDto.getIndicatorWeightValue();
            smokeMessage = minSmokeInfo.getMsg();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), smokeDto.getCreateTime(), currentTime, smokeDto.getIndicatorFirstLevelCode(), smokeDto.getIndicatorSecondLevelCode(), smokeDto.getIndicatorThirdLevelCode(), smokeScores, String.valueOf(minSmoke), minSmokeInfo.getMsg()));
        }
        //temperature_scores
        SysIndicatorDto temperatureDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.COALFACE_TEMPERATURE)).findFirst().orElse(null);
        if (temperatureDto != null) {
            AlarmInfoDto minSmokeInfo = getMinTemperatureInfo();
            float minSmoke = minSmokeInfo.getValue();
            temperatureScores = minSmoke * temperatureDto.getIndicatorWeightValue();
            temperatureMessage = minSmokeInfo.getMsg();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), temperatureDto.getCreateTime(), currentTime, temperatureDto.getIndicatorFirstLevelCode(), temperatureDto.getIndicatorSecondLevelCode(), temperatureDto.getIndicatorThirdLevelCode(), temperatureScores, String.valueOf(minSmoke), minSmokeInfo.getMsg()));
        }
        //keygas_scores
        SysIndicatorDto keyGasDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.KEYGAS_MONITOR_EARLY_WARNING)).findFirst().orElse(null);
        if (keyGasDto != null) {
            AlarmInfoDto minSmokeInfo = getMinKeyGasInfo();
            float minSmoke = minSmokeInfo.getValue();
            keyGasScores = minSmoke * keyGasDto.getIndicatorWeightValue();
            keyGasMessage = minSmokeInfo.getMsg();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), keyGasDto.getCreateTime(), currentTime, keyGasDto.getIndicatorFirstLevelCode(), keyGasDto.getIndicatorSecondLevelCode(), keyGasDto.getIndicatorThirdLevelCode(), keyGasScores, String.valueOf(minSmoke), minSmokeInfo.getMsg()));
        }
        //external_fire_scores
        SysIndicatorDto externalFireDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.FireDisasterConstant.EXTERNAL_FIRE_RISK_LEVEL) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (externalFireDto != null) {
            float orginalExternalFireScores = smokeScores + temperatureScores + keyGasScores;
            // TODO 模拟值
            orginalExternalFireScores = 80;
            float externalFireScore = orginalExternalFireScores * externalFireDto.getIndicatorWeightValue();
            String externalFireMessage = String.format("外因火灾安全态势判定，基于烟雾、温度、标志性气体的报警数据：%s, %s %s", smokeMessage, temperatureMessage, keyGasMessage);
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), externalFireDto.getCreateTime(), currentTime, externalFireDto.getIndicatorFirstLevelCode(), externalFireDto.getIndicatorSecondLevelCode(), externalFireDto.getIndicatorThirdLevelCode(), externalFireScore, String.valueOf(orginalExternalFireScores), externalFireMessage));
        }

        float safetyAwarenessScores = 0.0f;
        float fireRescueScores = 0.0f;
        float jobQualificationScores = 0.0f;
        //safety_awareness_scores
        SysIndicatorDto safetyAwarenessDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.SAFETY_AWARENESS_COAL_MINEFIRE)).findFirst().orElse(null);
        if (safetyAwarenessDto != null) {
            String indicatorValue = safetyAwarenessDto.getIndicatorValue();
            safetyAwarenessScores = Float.parseFloat(indicatorValue) * safetyAwarenessDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), safetyAwarenessDto.getCreateTime(), currentTime, safetyAwarenessDto.getIndicatorFirstLevelCode(), safetyAwarenessDto.getIndicatorSecondLevelCode(), safetyAwarenessDto.getIndicatorThirdLevelCode(), safetyAwarenessScores, safetyAwarenessDto.getIndicatorValue(), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //fire_rescue_scores
        SysIndicatorDto fireRescueDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE_RESCUE_SELF_RESCURE_CAPABILITY)).findFirst().orElse(null);
        if (fireRescueDto != null) {
            String indicatorValue = fireRescueDto.getIndicatorValue();
            fireRescueScores = Float.parseFloat(indicatorValue) * fireRescueDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), fireRescueDto.getCreateTime(), currentTime, fireRescueDto.getIndicatorFirstLevelCode(), fireRescueDto.getIndicatorSecondLevelCode(), fireRescueDto.getIndicatorThirdLevelCode(), fireRescueScores, fireRescueDto.getIndicatorValue(), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //job_qualification_scores
        SysIndicatorDto jobQualificationDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.JOB_QUALIFICATION_AND_ABILITY)).findFirst().orElse(null);
        if (jobQualificationDto != null) {
            String indicatorValue = jobQualificationDto.getIndicatorValue();
            jobQualificationScores = Float.parseFloat(indicatorValue) * jobQualificationDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), jobQualificationDto.getCreateTime(), currentTime, jobQualificationDto.getIndicatorFirstLevelCode(), jobQualificationDto.getIndicatorSecondLevelCode(), jobQualificationDto.getIndicatorThirdLevelCode(), jobQualificationScores, jobQualificationDto.getIndicatorValue(), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //fire_staff_scores
        SysIndicatorDto jobQualificationAndAbilityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.FireDisasterConstant.STAFF_SAFETY_QUALITY) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (jobQualificationAndAbilityDto != null) {
            float orginalJobQualificationAndAbilityScores = safetyAwarenessScores + fireRescueScores + jobQualificationScores;
            float jobQualificationAndAbilityScores = orginalJobQualificationAndAbilityScores * jobQualificationAndAbilityDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), jobQualificationAndAbilityDto.getCreateTime(), currentTime, jobQualificationAndAbilityDto.getIndicatorFirstLevelCode(), jobQualificationAndAbilityDto.getIndicatorSecondLevelCode(), jobQualificationAndAbilityDto.getIndicatorThirdLevelCode(), jobQualificationAndAbilityScores, String.valueOf(orginalJobQualificationAndAbilityScores), ""));
        }
        float coalFireSafetyEducationTrainingScores = 0.0f;
        float responseAbilityToFireAccidentsScores = 0.0f;
        float fireAccidentPreventionInvestmentScores = 0.0f;
        //coal_fire_safety_education_training_scores
        SysIndicatorDto coalFireSafetyEducationTrainingDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.COALMINE_FIRE_SAFETY_EDUCATION_AND_TRAINING)).findFirst().orElse(null);
        if (coalFireSafetyEducationTrainingDto != null) {
            String indicatorValue = coalFireSafetyEducationTrainingDto.getIndicatorValue();
            coalFireSafetyEducationTrainingScores = Float.parseFloat(indicatorValue) * coalFireSafetyEducationTrainingDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalFireSafetyEducationTrainingDto.getCreateTime(), currentTime, coalFireSafetyEducationTrainingDto.getIndicatorFirstLevelCode(), coalFireSafetyEducationTrainingDto.getIndicatorSecondLevelCode(), coalFireSafetyEducationTrainingDto.getIndicatorThirdLevelCode(), coalFireSafetyEducationTrainingScores, indicatorValue, AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //response_ability_to_fire_accidents_scores
        SysIndicatorDto responseAbilityToFireAccidentsDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.RESPONSE_ABILITY_TO_FIRE_ACCIDENTS)).findFirst().orElse(null);
        if (responseAbilityToFireAccidentsDto != null) {
            String indicatorValue = responseAbilityToFireAccidentsDto.getIndicatorValue();
            responseAbilityToFireAccidentsScores = Float.parseFloat(indicatorValue) * responseAbilityToFireAccidentsDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), responseAbilityToFireAccidentsDto.getCreateTime(), currentTime, responseAbilityToFireAccidentsDto.getIndicatorFirstLevelCode(), responseAbilityToFireAccidentsDto.getIndicatorSecondLevelCode(), responseAbilityToFireAccidentsDto.getIndicatorThirdLevelCode(), responseAbilityToFireAccidentsScores, indicatorValue, AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //fire_accident_prevention_investment_scores
        SysIndicatorDto fireAccidentPreventionInvestmentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE_ACCIDENT_PREVENTION_INVESTMENT)).findFirst().orElse(null);
        if (fireAccidentPreventionInvestmentDto != null) {
            String indicatorValue = fireAccidentPreventionInvestmentDto.getIndicatorValue();
            fireAccidentPreventionInvestmentScores = Float.parseFloat(indicatorValue) * fireAccidentPreventionInvestmentDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), fireAccidentPreventionInvestmentDto.getCreateTime(), currentTime, fireAccidentPreventionInvestmentDto.getIndicatorFirstLevelCode(), fireAccidentPreventionInvestmentDto.getIndicatorSecondLevelCode(), fireAccidentPreventionInvestmentDto.getIndicatorThirdLevelCode(), fireAccidentPreventionInvestmentScores, indicatorValue, AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //fire_management
        SysIndicatorDto fireManagementDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.FireDisasterConstant.FIRE_SAFETY_MANAGEMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (fireManagementDto != null) {
            float fireSafetyManagementScores = coalFireSafetyEducationTrainingScores + responseAbilityToFireAccidentsScores + fireAccidentPreventionInvestmentScores;
            float fireManagementScores = fireSafetyManagementScores * fireManagementDto.getIndicatorWeightValue();
            fireJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), fireManagementDto.getCreateTime(), currentTime, fireManagementDto.getIndicatorFirstLevelCode(), fireManagementDto.getIndicatorSecondLevelCode(), fireManagementDto.getIndicatorThirdLevelCode(), fireManagementScores, String.valueOf(fireSafetyManagementScores), ""));
        }
        if (CollectionUtils.isNotEmpty(fireJudgeModelList)) {
            minerService.batchInsertWeightScores(fireJudgeModelList);
        }
    }

    private AlarmInfoDto getMinKeyGasInfo() {
        AlarmInfoDto result = new AlarmInfoDto(0.0f, "");
        Float keyGasCoefficient = analysisConfig.getFireCoefficient().get("keygas_coefficient");
        List<Float> gasValue = Lists.newArrayList();
        //机电硐室关键气体
        SensorAlarmDto electricalChamberGas = new SensorAlarmDto(0, 0);
        float electromechanicalChamberKeyGasScores = FireRuleUtil.getKeyGasConcentrationScores(electricalChamberGas.getAlarmCount(), keyGasCoefficient, electricalChamberGas.getInterval());
        gasValue.add(electromechanicalChamberKeyGasScores);
        //制氮机房关键气体
        SensorAlarmDto nitrogenGas = new SensorAlarmDto(0, 0);
        float nitrogenRoomKeyGasScores = FireRuleUtil.getKeyGasConcentrationScores(nitrogenGas.getAlarmCount(), keyGasCoefficient, nitrogenGas.getInterval());
        gasValue.add(nitrogenRoomKeyGasScores);
        //黄泥灌浆关键气体
        SensorAlarmDto mudGas = new SensorAlarmDto(0, 0);
        float mudGasScores = FireRuleUtil.getKeyGasConcentrationScores(mudGas.getAlarmCount(), keyGasCoefficient, mudGas.getInterval());
        gasValue.add(mudGasScores);
        //工业场地关键气体
        SensorAlarmDto industrialGas = new SensorAlarmDto(0, 0);
        float industrialGasScores = FireRuleUtil.getKeyGasConcentrationScores(industrialGas.getAlarmCount(), keyGasCoefficient, industrialGas.getInterval());
        gasValue.add(industrialGasScores);
        //变电站关键气体
        SensorAlarmDto substationGas = new SensorAlarmDto(0, 0);
        float substationGasScores = FireRuleUtil.getKeyGasConcentrationScores(substationGas.getAlarmCount(), keyGasCoefficient, substationGas.getInterval());
        gasValue.add(substationGasScores);
        //风井场地关键气体
        SensorAlarmDto airGroundGas = new SensorAlarmDto(0, 0);
        float airGroundGasScores = FireRuleUtil.getKeyGasConcentrationScores(airGroundGas.getAlarmCount(), keyGasCoefficient, airGroundGas.getInterval());
        gasValue.add(airGroundGasScores);
        //胶带运输关键气体
        SensorAlarmDto beltGas = new SensorAlarmDto(0, 0);
        float beltGasScores = FireRuleUtil.getKeyGasConcentrationScores(beltGas.getAlarmCount(), keyGasCoefficient, beltGas.getInterval());
        gasValue.add(beltGasScores);
        result.setValue(gasValue.stream().min(Comparator.comparing(Float::floatValue)).orElse(0.0f));
        int i = gasValue.indexOf(result.getValue());
        switch (i) {
            case 1:
                result.setMsg(String.format("机电硐室标志性气体, 报警次数：%s, 超标时长：%s", electricalChamberGas.getAlarmCount(), electricalChamberGas.getInterval()));
                break;
            case 2:
                result.setMsg(String.format("制氮机房标志性气体, 报警次数：%s, 超标时长：%s", nitrogenGas.getAlarmCount(), nitrogenGas.getInterval()));
                break;
            case 3:
                result.setMsg(String.format("黄泥灌浆标志性气体, 报警次数：%s, 超标时长：%s", mudGas.getAlarmCount(), mudGas.getInterval()));
                break;
            case 4:
                result.setMsg(String.format("工业场地标志性气体, 报警次数：%s, 超标时长：%s", industrialGas.getAlarmCount(), industrialGas.getInterval()));
                break;
            case 5:
                result.setMsg(String.format("变电站标志性气体, 报警次数：%s, 超标时长：%s", substationGas.getAlarmCount(), substationGas.getInterval()));
                break;
            case 6:
                result.setMsg(String.format("风井场地标志性气体, 报警次数：%s, 超标时长：%s", airGroundGas.getAlarmCount(), airGroundGas.getInterval()));
                break;
            case 7:
                result.setMsg(String.format("胶带运输标志性气体, 报警次数：%s, 超标时长：%s", beltGas.getAlarmCount(), beltGas.getInterval()));
                break;
            default:
                result.setMsg(String.format("胶带运输标志性气体, 报警次数：%s, 超标时长：%s", 0, 0));
                break;
        }
        return result;
    }

    private AlarmInfoDto getMinTemperatureInfo() {
        AlarmInfoDto result = new AlarmInfoDto(0.0f, "");
        List<Float> tempValue = Lists.newArrayList();
        Float temperatureCoefficient = analysisConfig.getFireCoefficient().get("temperature_coefficient");
        //机电硐室温度
        SensorAlarmDto electricalChamberTemperature = new SensorAlarmDto(0, 0);
        float electromechanicalChamberTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(electricalChamberTemperature.getAlarmCount(), temperatureCoefficient);
        tempValue.add(electromechanicalChamberTemperatureScores);
        //制氮机房 灌浆机房的温度指标 由于没有资料支撑设置温度报警阈值，因此该两项指标均给满分
        //制氮机房温度
        SensorAlarmDto nitrogenTemperature = new SensorAlarmDto(0, 0);
        float nitrogenRoomTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(nitrogenTemperature.getAlarmCount(), temperatureCoefficient);
        //TODO 写死100
        nitrogenRoomTemperatureScores = 100f;
        tempValue.add(nitrogenRoomTemperatureScores);
        //黄泥灌浆温度
        SensorAlarmDto mudTemperature = new SensorAlarmDto(0, 0);
        float groutingMachineRoomTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(mudTemperature.getAlarmCount(), temperatureCoefficient);
        //TODO 写死100
        groutingMachineRoomTemperatureScores = 100f;
        tempValue.add(groutingMachineRoomTemperatureScores);
        //工业场地温度
        SensorAlarmDto industrialTemperature = new SensorAlarmDto(0, 0);
        float industrialTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(industrialTemperature.getAlarmCount(), temperatureCoefficient);
        tempValue.add(industrialTemperatureScores);
        //变电站温度
        SensorAlarmDto substationTemperature = new SensorAlarmDto(0, 0);
        float substationTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(substationTemperature.getAlarmCount(), temperatureCoefficient);
        tempValue.add(substationTemperatureScores);
        //风井场地温度
        SensorAlarmDto airGroundTemperature = new SensorAlarmDto(0, 0);
        float airShaftCableTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(airGroundTemperature.getAlarmCount(), temperatureCoefficient);
        tempValue.add(airShaftCableTemperatureScores);
        //胶带运输温度
        SensorAlarmDto beltTemperature = new SensorAlarmDto(0, 0);
        float beltTemperatureScores = FireRuleUtil.getTemperatureConcentrationScores(beltTemperature.getAlarmCount(), temperatureCoefficient);
        tempValue.add(beltTemperatureScores);
        result.setValue(tempValue.stream().min(Float::compareTo).orElse(0.0f));
        int i = tempValue.indexOf(result.getValue());
        switch (i) {
            case 1:
                result.setMsg(String.format("机电硐室温度, 报警次数：%s", electricalChamberTemperature.getAlarmCount()));
                break;
            case 2:
                result.setMsg(String.format("制氮机房温度, 报警次数：%s", nitrogenTemperature.getAlarmCount()));
                break;
            case 3:
                result.setMsg(String.format("黄泥灌浆温度, 报警次数：%s", mudTemperature.getAlarmCount()));
                break;
            case 4:
                result.setMsg(String.format("工业场地温度, 报警次数：%s", industrialTemperature.getAlarmCount()));
                break;
            case 5:
                result.setMsg(String.format("变电站温度, 报警次数：%s", substationTemperature.getAlarmCount()));
                break;
            case 6:
                result.setMsg(String.format("风井场地温度, 报警次数：%s", airGroundTemperature.getAlarmCount()));
                break;
            case 7:
                result.setMsg(String.format("胶带运输温度, 报警次数：%s", beltTemperature.getAlarmCount()));
                break;
            default:
                result.setMsg(String.format("胶带运输温度, 报警次数：%s", 0));
                break;
        }
        return result;
    }

    private AlarmInfoDto getMinSmokeInfo() {
        AlarmInfoDto result = new AlarmInfoDto(0.0f, "");
        List<Float> smokeValue = Lists.newArrayList();
        //机电硐室烟雾
        SensorAlarmDto electricalChamberSmoke = new SensorAlarmDto(0, 0);
        Float smokeCoefficient = analysisConfig.getFireCoefficient().get("smoke_coefficient");
        float electromechanicalChamberSmokeScores = FireRuleUtil.getSmokeConcentrationScores(electricalChamberSmoke.getAlarmCount(), smokeCoefficient, electricalChamberSmoke.getInterval());
        smokeValue.add(electromechanicalChamberSmokeScores);
        //制氮机房烟雾
        SensorAlarmDto nitrogenSmoke = new SensorAlarmDto(0, 0);
        float nitrogenRoomSmokeScores = FireRuleUtil.getSmokeConcentrationScores(nitrogenSmoke.getAlarmCount(), smokeCoefficient, nitrogenSmoke.getInterval());
        smokeValue.add(nitrogenRoomSmokeScores);
        //代表黄泥灌浆烟雾
        SensorAlarmDto mudSmoke = new SensorAlarmDto(0, 0);
        float groutingMachineRoomSmokeScores = FireRuleUtil.getSmokeConcentrationScores(mudSmoke.getAlarmCount(), smokeCoefficient, mudSmoke.getInterval());
        smokeValue.add(groutingMachineRoomSmokeScores);
        //工业场地烟雾
        SensorAlarmDto industrialSmoke = new SensorAlarmDto(0, 0);
        float cableChannelSmokeScores = FireRuleUtil.getSmokeConcentrationScores(industrialSmoke.getAlarmCount(), smokeCoefficient, industrialSmoke.getInterval());
        smokeValue.add(cableChannelSmokeScores);
        //变电站烟雾
        SensorAlarmDto substationSmoke = new SensorAlarmDto(0, 0);
        float substationCableSmokeScores = FireRuleUtil.getSmokeConcentrationScores(substationSmoke.getAlarmCount(), smokeCoefficient, substationSmoke.getInterval());
        smokeValue.add(substationCableSmokeScores);
        //风井场地烟雾
        //地面烟雾
        SensorAlarmDto airGroundSmoke = new SensorAlarmDto(0, 0);
        float airShaftCableSmokeScores = FireRuleUtil.getSmokeConcentrationScores(airGroundSmoke.getAlarmCount(), smokeCoefficient, airGroundSmoke.getInterval());
        smokeValue.add(airShaftCableSmokeScores);
        //胶带运输烟雾预警
        SensorAlarmDto beltSmoke = new SensorAlarmDto(0, 0);
        float beltTransSmokeScores = FireRuleUtil.getSmokeConcentrationScores(beltSmoke.getAlarmCount(), smokeCoefficient, beltSmoke.getInterval());
        smokeValue.add(beltTransSmokeScores);
        result.setValue(smokeValue.stream().min(Float::compareTo).orElse(0.0f));
        int i = smokeValue.indexOf(result.getValue());
        switch (i) {
            case 1:
                result.setMsg(String.format("机电硐室烟雾, 报警次数：%s, 超标时长：%s", electricalChamberSmoke.getAlarmCount(), electricalChamberSmoke.getInterval()));
                break;
            case 2:
                result.setMsg(String.format("制氮机房烟雾, 报警次数：%s, 超标时长：%s", nitrogenSmoke.getAlarmCount(), nitrogenSmoke.getInterval()));
                break;
            case 3:
                result.setMsg(String.format("黄泥灌浆烟雾, 报警次数：%s, 超标时长：%s", mudSmoke.getAlarmCount(), mudSmoke.getInterval()));
                break;
            case 4:
                result.setMsg(String.format("工业场地烟雾, 报警次数：%s, 超标时长：%s", industrialSmoke.getAlarmCount(), industrialSmoke.getInterval()));
                break;
            case 5:
                result.setMsg(String.format("变电站烟雾, 报警次数：%s, 超标时长：%s", substationSmoke.getAlarmCount(), substationSmoke.getInterval()));
                break;
            case 6:
                result.setMsg(String.format("风井场地烟雾, 报警次数：%s, 超标时长：%s", airGroundSmoke.getAlarmCount(), airGroundSmoke.getInterval()));
                break;
            case 7:
                result.setMsg(String.format("胶带运输烟雾, 报警次数：%s, 超标时长：%s", beltSmoke.getAlarmCount(), beltSmoke.getInterval()));
                break;
            default:
                result.setMsg(String.format("胶带运输烟雾, 报警次数：%s, 超标时长：%s", 0, 0));
                break;
        }
        return result;
    }


    private void mineWaterJudge(List<SysIndicatorDto> sysIndicatorList, Date currentTime) {
        List<SysMineIndicatorModel> waterJudgeModelList = Lists.newArrayList();
        float resistivityScores = 0.0f;
        float lhTemperatureScores = 0.0f;
        float lhLevelScores = 0.0f;
        float closedWallTemperatureScores = 0.0f;
        float closedWallLevelScores = 0.0f;
        float drainageScores = 0.0f;
        float maxWaterInflowScores = 0.0f;
        float hydrogeologicalScores = 0.0f;
        float surfaceWaterScores = 0.0f;
        float faultStructuralScores = 0.0f;
        float oldEmptyWaterScores = 0.0f;
        //resistivity
        SysIndicatorDto resistivityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.RESISTIVITY)).findFirst().orElse(null);
        if (resistivityDto != null) {
            String educationPercent = resistivityDto.getIndicatorValue();
            float electricMethodEvaluationScores = WaterRuleUtil.getResistivityScores(Float.parseFloat(educationPercent));
            // TODO 指标值被写死
            electricMethodEvaluationScores = 85;
            resistivityScores = electricMethodEvaluationScores * resistivityDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), resistivityDto.getCreateTime(), currentTime, resistivityDto.getIndicatorFirstLevelCode(), resistivityDto.getIndicatorSecondLevelCode(), resistivityDto.getIndicatorThirdLevelCode(), resistivityScores, String.valueOf(electricMethodEvaluationScores), resistivityDto.getIndicatorReason()));
        }
        //lh_temperature
        SysIndicatorDto lhTemperatureDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.LONG_VIEW_HOLE_WATER_TEMPERATURE)).findFirst().orElse(null);
        if (lhTemperatureDto != null) {
            String educationPercent = lhTemperatureDto.getIndicatorValue();
            float longHoleViewTemperatureScore = WaterRuleUtil.getLongholeViewWaterTemperatureScores(Float.parseFloat(educationPercent));
            // TODO 指标值被写死
            longHoleViewTemperatureScore = 85;
            lhTemperatureScores = longHoleViewTemperatureScore * lhTemperatureDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), lhTemperatureDto.getCreateTime(), currentTime, lhTemperatureDto.getIndicatorFirstLevelCode(), lhTemperatureDto.getIndicatorSecondLevelCode(), lhTemperatureDto.getIndicatorThirdLevelCode(), lhTemperatureScores, String.valueOf(longHoleViewTemperatureScore), lhTemperatureDto.getIndicatorReason()));
        }
        //lh_level_scores
        SysIndicatorDto lhLevelDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.LONG_VIEW_HOLE_WATER_LEVEL)).findFirst().orElse(null);
        if (lhLevelDto != null) {
            String educationPercent = lhLevelDto.getIndicatorValue();
            float longHoleViewWaterLevleScore = WaterRuleUtil.getLongholeViewWaterLevelScores(Float.parseFloat(educationPercent));
            // TODO 指标值被写死
            longHoleViewWaterLevleScore = 85;
            lhLevelScores = longHoleViewWaterLevleScore * lhLevelDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), lhLevelDto.getCreateTime(), currentTime, lhLevelDto.getIndicatorFirstLevelCode(), lhLevelDto.getIndicatorSecondLevelCode(), lhLevelDto.getIndicatorThirdLevelCode(), lhLevelScores, String.valueOf(longHoleViewWaterLevleScore), lhLevelDto.getIndicatorReason()));
        }
        //closed_wall_temperature_scores
        SysIndicatorDto closedWallTemperatureDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.CLOSED_WALL_WATER_TEMPERATURE)).findFirst().orElse(null);
        if (closedWallTemperatureDto != null) {
            String educationPercent = closedWallTemperatureDto.getIndicatorValue();
            float closedWallTemperatureScore = WaterRuleUtil.getForbiddenWallWaterTemperatureScores(Float.parseFloat(educationPercent));
            // TODO 指标值被写死
            closedWallTemperatureScore = 85;
            closedWallTemperatureScores = closedWallTemperatureScore * closedWallTemperatureDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), closedWallTemperatureDto.getCreateTime(), currentTime, closedWallTemperatureDto.getIndicatorFirstLevelCode(), closedWallTemperatureDto.getIndicatorSecondLevelCode(), closedWallTemperatureDto.getIndicatorThirdLevelCode(), closedWallTemperatureScores, String.valueOf(closedWallTemperatureScore), closedWallTemperatureDto.getIndicatorReason()));
        }
        //closed_wall_level_scores
        SysIndicatorDto closedWallLevelDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.CLOSED_WALL_WATER_LEVEL)).findFirst().orElse(null);
        if (closedWallLevelDto != null) {
            String educationPercent = closedWallLevelDto.getIndicatorValue();
            float closedWallLevelScore = WaterRuleUtil.getForbiddenWallWaterLevelScores(Float.parseFloat(educationPercent));
            // TODO 指标值被写死
            closedWallLevelScore = 85;
            closedWallLevelScores = closedWallLevelScore * closedWallLevelDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), closedWallLevelDto.getCreateTime(), currentTime, closedWallLevelDto.getIndicatorFirstLevelCode(), closedWallLevelDto.getIndicatorSecondLevelCode(), closedWallLevelDto.getIndicatorThirdLevelCode(), closedWallLevelScores, String.valueOf(closedWallLevelScore), closedWallLevelDto.getIndicatorReason()));
        }
        //drainage_scores
        SysIndicatorDto drainageDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.DAILY_CUMULATIVE_DISCAHRGE)).findFirst().orElse(null);
        if (drainageDto != null) {
            String educationPercent = drainageDto.getIndicatorValue();
            String[] split = educationPercent.split("_");
            float drainageScore = WaterRuleUtil.getDailyCumulativeDischarge(Float.parseFloat(split[0]), Float.parseFloat(split[0]));
            drainageScores = drainageScore * drainageDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), drainageDto.getCreateTime(), currentTime, drainageDto.getIndicatorFirstLevelCode(), drainageDto.getIndicatorSecondLevelCode(), drainageDto.getIndicatorThirdLevelCode(), drainageScores, String.valueOf(drainageScore), drainageDto.getIndicatorReason()));
        }
        //max_waterinflow_scores
        SysIndicatorDto maxWaterInflowDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.MAX_DAILY_WATER_INFLOW)).findFirst().orElse(null);
        if (maxWaterInflowDto != null) {
            String educationPercent = maxWaterInflowDto.getIndicatorValue();
            float maxWaterInflowScore = WaterRuleUtil.getMaxWaterInflow(Float.parseFloat(educationPercent));
            maxWaterInflowScores = maxWaterInflowScore * maxWaterInflowDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), maxWaterInflowDto.getCreateTime(), currentTime, maxWaterInflowDto.getIndicatorFirstLevelCode(), maxWaterInflowDto.getIndicatorSecondLevelCode(), maxWaterInflowDto.getIndicatorThirdLevelCode(), maxWaterInflowScores, String.valueOf(maxWaterInflowScore), maxWaterInflowDto.getIndicatorReason()));
        }
        //hydrogeological_scores
        SysIndicatorDto hydrogeologicalDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.HYDROGEOLOGICAL_TYPE)).findFirst().orElse(null);
        if (hydrogeologicalDto != null) {
            String educationPercent = hydrogeologicalDto.getIndicatorValue();
            float hydrogeologicalScore = WaterRuleUtil.getHydrogeologicalTypeScores(Integer.parseInt(educationPercent));
            hydrogeologicalScores = hydrogeologicalScore * hydrogeologicalDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), hydrogeologicalDto.getCreateTime(), currentTime, hydrogeologicalDto.getIndicatorFirstLevelCode(), hydrogeologicalDto.getIndicatorSecondLevelCode(), hydrogeologicalDto.getIndicatorThirdLevelCode(), hydrogeologicalScores, String.valueOf(hydrogeologicalScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //surfacewater_scores
        SysIndicatorDto surfaceWaterDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.SURFACE_WATER)).findFirst().orElse(null);
        if (surfaceWaterDto != null) {
            String educationPercent = surfaceWaterDto.getIndicatorValue();
            float surfaceWaterScore = WaterRuleUtil.getFloorWaterScores(Integer.parseInt(educationPercent));
            surfaceWaterScores = surfaceWaterScore * surfaceWaterDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), surfaceWaterDto.getCreateTime(), currentTime, surfaceWaterDto.getIndicatorFirstLevelCode(), surfaceWaterDto.getIndicatorSecondLevelCode(), surfaceWaterDto.getIndicatorThirdLevelCode(), surfaceWaterScores, String.valueOf(surfaceWaterScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //fault_structural_karst_water_scores
        SysIndicatorDto faultStructuralDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.FAULT_STRUCTURAL_WATER_AND_KARST_WATER)).findFirst().orElse(null);
        if (faultStructuralDto != null) {
            String educationPercent = faultStructuralDto.getIndicatorValue();
            float faultStructuralScore = WaterRuleUtil.getFaultStructuralAndKarstWaterScores(Integer.parseInt(educationPercent));
            faultStructuralScores = faultStructuralScore * faultStructuralDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), faultStructuralDto.getCreateTime(), currentTime, faultStructuralDto.getIndicatorFirstLevelCode(), faultStructuralDto.getIndicatorSecondLevelCode(), faultStructuralDto.getIndicatorThirdLevelCode(), faultStructuralScores, String.valueOf(faultStructuralScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //old_empty_water
        SysIndicatorDto oldEmptyWaterDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.OLD_EMPTY_WATER)).findFirst().orElse(null);
        if (oldEmptyWaterDto != null) {
            String educationPercent = oldEmptyWaterDto.getIndicatorValue();
            float oldEmptyWaterScore = WaterRuleUtil.getWaterEmpty(Integer.parseInt(educationPercent));
            oldEmptyWaterScores = oldEmptyWaterScore * oldEmptyWaterDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), oldEmptyWaterDto.getCreateTime(), currentTime, oldEmptyWaterDto.getIndicatorFirstLevelCode(), oldEmptyWaterDto.getIndicatorSecondLevelCode(), oldEmptyWaterDto.getIndicatorThirdLevelCode(), oldEmptyWaterScores, String.valueOf(oldEmptyWaterScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //water_enviorment_scores
        SysIndicatorDto waterEnviormentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_ENVIORMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (waterEnviormentDto != null) {
            float originalWaterEnviormentScores = resistivityScores + lhTemperatureScores + lhLevelScores + closedWallTemperatureScores + closedWallLevelScores + drainageScores + maxWaterInflowScores + hydrogeologicalScores + surfaceWaterScores + faultStructuralScores + oldEmptyWaterScores;
            float waterEnviormentScores = originalWaterEnviormentScores * waterEnviormentDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterEnviormentDto.getCreateTime(), currentTime, waterEnviormentDto.getIndicatorFirstLevelCode(), waterEnviormentDto.getIndicatorSecondLevelCode(), waterEnviormentDto.getIndicatorThirdLevelCode(), waterEnviormentScores, String.valueOf(originalWaterEnviormentScores), waterEnviormentDto.getIndicatorReason()));
        }

        float annualWaterPlanScores = 0f;
        float longtermPlanWaterControlScores = 0f;
        float waterPreventionOriginazationScores = 0f;
        float waterhazardAccountScores = 0f;
        float investigateWaterScores = 0f;
        float waterDisasterEmergencyPlan = 0f;
        float emergencyWaterYearScores = 0f;
        //annual_water_plan_scores
        SysIndicatorDto annualWaterPlanDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.ANNUAL_WATER_CONTROL_PLAN)).findFirst().orElse(null);
        if (annualWaterPlanDto != null) {
            String educationPercent = annualWaterPlanDto.getIndicatorValue();
            float annualWaterPlanScore = WaterRuleUtil.getAnnualWaterControlPlanScores(Integer.parseInt(educationPercent));
            annualWaterPlanScores = annualWaterPlanScore * annualWaterPlanDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), annualWaterPlanDto.getCreateTime(), currentTime, annualWaterPlanDto.getIndicatorFirstLevelCode(), annualWaterPlanDto.getIndicatorSecondLevelCode(), annualWaterPlanDto.getIndicatorThirdLevelCode(), annualWaterPlanScores, String.valueOf(annualWaterPlanScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //longterm_plan_water_control_scores
        SysIndicatorDto longtermPlanWaterControlDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.LONG_TERM_PLAN_WATER_PREVENTION_AND_CONTROL)).findFirst().orElse(null);
        if (longtermPlanWaterControlDto != null) {
            String educationPercent = longtermPlanWaterControlDto.getIndicatorValue();
            float longtermPlanWaterControlScore = WaterRuleUtil.getLongTermWaterControlPlanScores(Integer.parseInt(educationPercent));
            longtermPlanWaterControlScores = longtermPlanWaterControlScore * longtermPlanWaterControlDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), longtermPlanWaterControlDto.getCreateTime(), currentTime, longtermPlanWaterControlDto.getIndicatorFirstLevelCode(), longtermPlanWaterControlDto.getIndicatorSecondLevelCode(), longtermPlanWaterControlDto.getIndicatorThirdLevelCode(), longtermPlanWaterControlScores, String.valueOf(longtermPlanWaterControlScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //water_prevention_originazation_scores
        SysIndicatorDto waterPreventionOriginazationDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_PREVENTION_CONTROL_ORGANIZATION)).findFirst().orElse(null);
        if (waterPreventionOriginazationDto != null) {
            String indicatorValue = waterPreventionOriginazationDto.getIndicatorValue();
            float originalWaterPreventionOriginazationScores = WaterRuleUtil.getWaterControlOrganizationScores(Integer.parseInt(indicatorValue));
            waterPreventionOriginazationScores = originalWaterPreventionOriginazationScores * waterPreventionOriginazationDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterPreventionOriginazationDto.getCreateTime(), currentTime, waterPreventionOriginazationDto.getIndicatorFirstLevelCode(), waterPreventionOriginazationDto.getIndicatorSecondLevelCode(), waterPreventionOriginazationDto.getIndicatorThirdLevelCode(), waterPreventionOriginazationScores, String.valueOf(originalWaterPreventionOriginazationScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //waterhazard_account_scores
        SysIndicatorDto waterhazardAccountDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.INTEGERIRY_RATE_OF_COAL_MINE_WATER_HAZARD_ACCOUNT)).findFirst().orElse(null);
        if (waterhazardAccountDto != null) {
            String indicatorValue = waterhazardAccountDto.getIndicatorValue();
            float waterhazardAccountScore = WaterRuleUtil.getIntegrityRateOfCoalMineWaterHazardAccountScores(Float.parseFloat(indicatorValue));
            waterhazardAccountScores = waterhazardAccountScore * waterhazardAccountDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterhazardAccountDto.getCreateTime(), currentTime, waterhazardAccountDto.getIndicatorFirstLevelCode(), waterhazardAccountDto.getIndicatorSecondLevelCode(), waterhazardAccountDto.getIndicatorThirdLevelCode(), waterhazardAccountScores, String.valueOf(waterhazardAccountScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //investigate_water_scores
        SysIndicatorDto investigateWaterDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.INVESTIGATION_WATER_HAZAARDS_BY_MONTH)).findFirst().orElse(null);
        if (investigateWaterDto != null) {
            String indicatorValue = investigateWaterDto.getIndicatorValue();
            float investigateWaterScore = WaterRuleUtil.getInvestigationWaterHazardsByMonth(Integer.parseInt(indicatorValue));
            investigateWaterScores = investigateWaterScore * investigateWaterDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), investigateWaterDto.getCreateTime(), currentTime, investigateWaterDto.getIndicatorFirstLevelCode(), investigateWaterDto.getIndicatorSecondLevelCode(), investigateWaterDto.getIndicatorThirdLevelCode(), investigateWaterScores, String.valueOf(investigateWaterScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //water_disaster_emergency_plan
        SysIndicatorDto waterDisasterEmergencyPlanDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_DISASTER_EMERGENCY_PLAN)).findFirst().orElse(null);
        if (waterDisasterEmergencyPlanDto != null) {
            String indicatorValue = waterDisasterEmergencyPlanDto.getIndicatorValue();
            float waterDisasterEmergencyPlanScore = WaterRuleUtil.getWaterDisasterEmergencyRescueByYearScores(Integer.parseInt(indicatorValue));
            waterDisasterEmergencyPlan = waterDisasterEmergencyPlanScore * waterDisasterEmergencyPlanDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterDisasterEmergencyPlanDto.getCreateTime(), currentTime, waterDisasterEmergencyPlanDto.getIndicatorFirstLevelCode(), waterDisasterEmergencyPlanDto.getIndicatorSecondLevelCode(), waterDisasterEmergencyPlanDto.getIndicatorThirdLevelCode(), waterDisasterEmergencyPlan, String.valueOf(waterDisasterEmergencyPlanScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //emergency_water_year_scores
        SysIndicatorDto emergencyWaterYearDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.EMERGENCY_RESCUSE_DRILL_FOR_WATER_DISASTER_BY_YEAR)).findFirst().orElse(null);
        if (emergencyWaterYearDto != null) {
            String indicatorValue = emergencyWaterYearDto.getIndicatorValue();
            float emergencyWaterYearScore = WaterRuleUtil.getWaterDisasterEmergencyRescueByYearScores(Integer.parseInt(indicatorValue));
            emergencyWaterYearScores = emergencyWaterYearScore * emergencyWaterYearDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), emergencyWaterYearDto.getCreateTime(), currentTime, emergencyWaterYearDto.getIndicatorFirstLevelCode(), emergencyWaterYearDto.getIndicatorSecondLevelCode(), emergencyWaterYearDto.getIndicatorThirdLevelCode(), emergencyWaterYearScores, String.valueOf(emergencyWaterYearScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //water_management_scores
        SysIndicatorDto waterManagementDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_MANAGEMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (waterManagementDto != null) {
            float originalWaterManagementScores = emergencyWaterYearScores + annualWaterPlanScores + longtermPlanWaterControlScores + waterPreventionOriginazationScores + waterhazardAccountScores + investigateWaterScores + waterDisasterEmergencyPlan;
            float waterManagementScores = originalWaterManagementScores * waterManagementDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterManagementDto.getCreateTime(), currentTime, waterManagementDto.getIndicatorFirstLevelCode(), waterManagementDto.getIndicatorSecondLevelCode(), waterManagementDto.getIndicatorThirdLevelCode(), waterManagementScores, String.valueOf(originalWaterManagementScores), waterManagementDto.getIndicatorReason()));
        }

        float ischiefExistScores = 0.0f;
        float waterproofEngineerScores = 0.0f;
        float waterreleaseTeamScores = 0.0f;
        float waterproofTrainingRateScores = 0.0f;
        // ischief_exist_scores
        SysIndicatorDto ischiefExistDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.IS_CHIEF_WATERPROOF_ENGINEER_EXIST)).findFirst().orElse(null);
        if (ischiefExistDto != null) {
            String indicatorValue = ischiefExistDto.getIndicatorValue();
            float oriChiefExistScores = WaterRuleUtil.getChiefWaterControlPreventionEngineerScores(Integer.parseInt(indicatorValue));
            ischiefExistScores = oriChiefExistScores * ischiefExistDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), ischiefExistDto.getCreateTime(), currentTime, ischiefExistDto.getIndicatorFirstLevelCode(), ischiefExistDto.getIndicatorSecondLevelCode(), ischiefExistDto.getIndicatorThirdLevelCode(), ischiefExistScores, String.valueOf(oriChiefExistScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //waterproof_engineer_scores
        SysIndicatorDto waterproofEngineerDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.WATERPROOF_ENGINEER_COUNT)).findFirst().orElse(null);
        if (waterproofEngineerDto != null) {
            String indicatorValue = waterproofEngineerDto.getIndicatorValue();
            float originalWaterproofEngineerScores = WaterRuleUtil.getWaterControlStaffCountScores(Integer.parseInt(indicatorValue));
            waterproofEngineerScores = originalWaterproofEngineerScores * waterproofEngineerDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterproofEngineerDto.getCreateTime(), currentTime, waterproofEngineerDto.getIndicatorFirstLevelCode(), waterproofEngineerDto.getIndicatorSecondLevelCode(), waterproofEngineerDto.getIndicatorThirdLevelCode(), waterproofEngineerScores, String.valueOf(originalWaterproofEngineerScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //waterrelease_team_scores
        SysIndicatorDto waterreleaseTeamDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.IS_WATER_RELEASE_TEAM_EXIST)).findFirst().orElse(null);
        if (waterreleaseTeamDto != null) {
            String indicatorValue = waterreleaseTeamDto.getIndicatorValue();
            float originalWaterreleaseTeamScores = WaterRuleUtil.getWaterExplorationTeamScores(Integer.parseInt(indicatorValue));
            waterreleaseTeamScores = originalWaterreleaseTeamScores * waterreleaseTeamDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterreleaseTeamDto.getCreateTime(), currentTime, waterreleaseTeamDto.getIndicatorFirstLevelCode(), waterreleaseTeamDto.getIndicatorSecondLevelCode(), waterreleaseTeamDto.getIndicatorThirdLevelCode(), waterreleaseTeamScores, String.valueOf(originalWaterreleaseTeamScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //waterproof_training_rate_scores
        SysIndicatorDto waterproofTrainingRateDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_PROOF_KNOWLEDGE_TRAINING_RATE)).findFirst().orElse(null);
        if (waterproofTrainingRateDto != null) {
            String indicatorValue = waterproofTrainingRateDto.getIndicatorValue();
            float originalWaterproofTrainingRateScores = WaterRuleUtil.getWaterPreventionTrainingPercentScores(Integer.parseInt(indicatorValue));
            waterproofTrainingRateScores = originalWaterproofTrainingRateScores * waterproofTrainingRateDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterproofTrainingRateDto.getCreateTime(), currentTime, waterproofTrainingRateDto.getIndicatorFirstLevelCode(), waterproofTrainingRateDto.getIndicatorSecondLevelCode(), waterproofTrainingRateDto.getIndicatorThirdLevelCode(), waterproofTrainingRateScores, String.valueOf(originalWaterproofTrainingRateScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //water_equip_scores
        SysIndicatorDto waterEquipDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_STAFF) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (waterEquipDto != null) {
            float originalWaterEquipScores = waterproofTrainingRateScores + waterreleaseTeamScores + waterproofEngineerScores + ischiefExistScores;
            float waterEquipScores = originalWaterEquipScores * waterEquipDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterEquipDto.getCreateTime(), currentTime, waterEquipDto.getIndicatorFirstLevelCode(), waterEquipDto.getIndicatorSecondLevelCode(), waterEquipDto.getIndicatorThirdLevelCode(), waterEquipScores, String.valueOf(originalWaterEquipScores), waterEquipDto.getIndicatorReason()));
        }

        float waterEquipThirdScores = 0.0f;
        float normalPumpCapacityScores = 0.0f;
        float standbyPumpCapacityScores = 0.0f;
        float checkPumpCapacityScores = 0.0f;
        float drainagePipelineScores = 0.0f;
        //water_release_eqip_scores
        SysIndicatorDto waterEquipThirdDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.IS_WATER_RELEASE_EQUIPMENT)).findFirst().orElse(null);
        if (waterEquipThirdDto != null) {
            String indicatorValue = waterEquipThirdDto.getIndicatorValue();
            float originalWaterEquipThirdScores = WaterRuleUtil.getWaterExplorationEquipmentScores(Integer.parseInt(indicatorValue));
            waterEquipThirdScores = originalWaterEquipThirdScores * waterEquipThirdDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterEquipThirdDto.getCreateTime(), currentTime, waterEquipThirdDto.getIndicatorFirstLevelCode(), waterEquipThirdDto.getIndicatorSecondLevelCode(), waterEquipThirdDto.getIndicatorThirdLevelCode(), waterEquipThirdScores, String.valueOf(originalWaterEquipThirdScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //normal_pump_capacity_scores
        SysIndicatorDto normalPumpCapacityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.NORMAL_PUMP_CAPACITY)).findFirst().orElse(null);
        if (normalPumpCapacityDto != null) {
            String indicatorValue = normalPumpCapacityDto.getIndicatorValue();
            float originalNormalPumpCapacityScores = WaterRuleUtil.getNormalPumpCapacityScores(Integer.parseInt(indicatorValue));
            normalPumpCapacityScores = originalNormalPumpCapacityScores * normalPumpCapacityDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), normalPumpCapacityDto.getCreateTime(), currentTime, normalPumpCapacityDto.getIndicatorFirstLevelCode(), normalPumpCapacityDto.getIndicatorSecondLevelCode(), normalPumpCapacityDto.getIndicatorThirdLevelCode(), normalPumpCapacityScores, String.valueOf(originalNormalPumpCapacityScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //standby_pump_capacity_scores
        SysIndicatorDto standbyPumpCapacityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.STANDBY_PUMP_CAPACITY)).findFirst().orElse(null);
        if (standbyPumpCapacityDto != null) {
            String indicatorValue = standbyPumpCapacityDto.getIndicatorValue();
            float originalStandbyPumpCapacityScores = WaterRuleUtil.getPreparedPumpCapacityScores(Integer.parseInt(indicatorValue));
            standbyPumpCapacityScores = originalStandbyPumpCapacityScores * standbyPumpCapacityDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), standbyPumpCapacityDto.getCreateTime(), currentTime, standbyPumpCapacityDto.getIndicatorFirstLevelCode(), standbyPumpCapacityDto.getIndicatorSecondLevelCode(), standbyPumpCapacityDto.getIndicatorThirdLevelCode(), standbyPumpCapacityScores, String.valueOf(originalStandbyPumpCapacityScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //check_pump_capacity_scores
        SysIndicatorDto checkPumpCapacityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.CHECK_PUMP_CAPACITY)).findFirst().orElse(null);
        if (checkPumpCapacityDto != null) {
            String indicatorValue = checkPumpCapacityDto.getIndicatorValue();
            float originalCheckPumpCapacityScores = WaterRuleUtil.getRepairPumpCapacityScores(Integer.parseInt(indicatorValue));
            checkPumpCapacityScores = originalCheckPumpCapacityScores * checkPumpCapacityDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), checkPumpCapacityDto.getCreateTime(), currentTime, checkPumpCapacityDto.getIndicatorFirstLevelCode(), checkPumpCapacityDto.getIndicatorSecondLevelCode(), checkPumpCapacityDto.getIndicatorThirdLevelCode(), checkPumpCapacityScores, String.valueOf(originalCheckPumpCapacityScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //drainage_pipeline_scores
        SysIndicatorDto drainagePipelineDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.DRAINAGE_PIPELINE_CAPACITY)).findFirst().orElse(null);
        if (drainagePipelineDto != null) {
            String indicatorValue = drainagePipelineDto.getIndicatorValue();
            float originalDrainagePipelineScores = WaterRuleUtil.getDrainagePipelineCapacityScores(Integer.parseInt(indicatorValue));
            drainagePipelineScores = originalDrainagePipelineScores * drainagePipelineDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), drainagePipelineDto.getCreateTime(), currentTime, drainagePipelineDto.getIndicatorFirstLevelCode(), drainagePipelineDto.getIndicatorSecondLevelCode(), drainagePipelineDto.getIndicatorThirdLevelCode(), drainagePipelineScores, String.valueOf(originalDrainagePipelineScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //water_equipment_scores
        SysIndicatorDto waterEquipmentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER_EQUIPMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (waterEquipmentDto != null) {
            float originalWaterEquipmentScores = waterEquipThirdScores + normalPumpCapacityScores + standbyPumpCapacityScores + checkPumpCapacityScores + drainagePipelineScores;
            float waterEquipmentScores = originalWaterEquipmentScores * waterEquipmentDto.getIndicatorWeightValue();
            waterJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), waterEquipmentDto.getCreateTime(), currentTime, waterEquipmentDto.getIndicatorFirstLevelCode(), waterEquipmentDto.getIndicatorSecondLevelCode(), waterEquipmentDto.getIndicatorThirdLevelCode(), waterEquipmentScores, String.valueOf(originalWaterEquipmentScores), waterEquipmentDto.getIndicatorReason()));
        }
        if (CollectionUtils.isNotEmpty(waterJudgeModelList)) {
            minerService.batchInsertWeightScores(waterJudgeModelList);
        }
    }

    private void processWaterDisaster(String lastBeginTime, String lastEndTime, String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        //日累计排水量
        setWaterdrainByDay(sysIndicatorList, endTime, lastBeginTime, lastEndTime);
        //累计涌水量
        setMaxWaterInflowDay(lastBeginTime, lastEndTime, sysIndicatorList);
        //长观孔水位  长观孔水温
        setMaxLongviewholeData(lastBeginTime, lastEndTime, sysIndicatorList);
        //电法数据
        setResistivityData(sysIndicatorList);
        //密闭墙孔水、水温
        setForbiddenWaterData(sysIndicatorList);
    }

    private void setForbiddenWaterData(List<SysIndicatorDto> sysIndicatorList) {
        SysIndicatorDto wallWaterLevelDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.CLOSED_WALL_WATER_LEVEL)).findFirst().orElse(null);
        if (wallWaterLevelDto != null) {
            wallWaterLevelDto.setIndicatorValue("0");
            wallWaterLevelDto.setIndicatorReason("无密闭墙水位数据，指标项评判数据要减分");
        }
        SysIndicatorDto wallWaterTemperatureDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.CLOSED_WALL_WATER_TEMPERATURE)).findFirst().orElse(null);
        if (wallWaterTemperatureDto != null) {
            wallWaterTemperatureDto.setIndicatorValue("0");
            wallWaterTemperatureDto.setIndicatorReason("无密闭墙孔水温数据，指标项评判数据要减分");
        }
    }

    private void setResistivityData(List<SysIndicatorDto> sysIndicatorList) {
        SysIndicatorDto resistivityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.RESISTIVITY)).findFirst().orElse(null);
        if (resistivityDto != null) {
            resistivityDto.setIndicatorValue("0");
            resistivityDto.setIndicatorReason("无电法数据， 指标项评判数据要减分");
        }
    }

    private void setMaxLongviewholeData(String lastBeginTime, String lastEndTime, List<SysIndicatorDto> sysIndicatorList) {
        List<LongViewHoleDto> longViewHoleList = safetyService.getLongViewHoleData(lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto holeWaterLevelDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.LONG_VIEW_HOLE_WATER_LEVEL)).findFirst().orElse(null);
        SysIndicatorDto holeWaterTemperatureDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.LONG_VIEW_HOLE_WATER_TEMPERATURE)).findFirst().orElse(null);
        if (holeWaterLevelDto != null) {
            if (CollectionUtils.isNotEmpty(longViewHoleList)) {
                longViewHoleList.sort(Comparator.comparing(LongViewHoleDto::getWaterLevelValue).reversed());
                float waterLevel = longViewHoleList.get(0).getWaterLevelValue() - 10;
                holeWaterLevelDto.setIndicatorValue(String.valueOf(waterLevel));
                holeWaterLevelDto.setIndicatorReason(String.format("长观孔水位 传感器位置 %s, 传感器编号 %s 长观孔水位变化幅度为 %s", longViewHoleList.get(0).getSensorLocation(), longViewHoleList.get(0).getPointCode(), waterLevel));
            } else {
                holeWaterLevelDto.setIndicatorValue("0");
                holeWaterLevelDto.setIndicatorReason("无长观孔水位数据，指标项评判数据要减分");
            }
        }
        if (holeWaterTemperatureDto != null) {
            if (CollectionUtils.isNotEmpty(longViewHoleList)) {
                longViewHoleList.sort(Comparator.comparing(LongViewHoleDto::getWaterTemperatureValue).reversed());
                float waterTemperature = longViewHoleList.get(0).getWaterTemperatureValue() - 10;
                holeWaterTemperatureDto.setIndicatorValue(String.valueOf(waterTemperature));
                holeWaterTemperatureDto.setIndicatorReason(String.format("长观孔水温 传感器位置 %s, 传感器编号 %s 长观孔水温变化幅度为 %s", longViewHoleList.get(0).getSensorLocation(), longViewHoleList.get(0).getPointCode(), waterTemperature));
            } else {
                holeWaterTemperatureDto.setIndicatorValue("0");
                holeWaterTemperatureDto.setIndicatorReason("无长观孔水温数据，指标项评判数据要减分");
            }
        }
    }

    private void setMaxWaterInflowDay(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        Float maxWaterInflowDay = safetyService.getWaterInflowDay(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto waterInflowDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.MAX_DAILY_WATER_INFLOW)).findFirst().orElse(null);
        if (waterInflowDto != null) {
            if (maxWaterInflowDay != null && maxWaterInflowDay > 0) {
                float tempValue = (maxWaterInflowDay / 1440) * 60;
                float waterPercent = (tempValue - 140) / 140 * 100;
                waterInflowDto.setIndicatorValue(String.valueOf(tempValue));
                waterInflowDto.setIndicatorReason(String.format("日累计涌水量 %s m³/h, 累计涌水量变化幅度为 %s%s", tempValue, waterPercent, "%"));
            } else {
                waterInflowDto.setIndicatorValue("0.0");
                waterInflowDto.setIndicatorReason("无累计涌水量，指标项评判数据要减分");
            }
        }
    }


    private void setWaterdrainByDay(List<SysIndicatorDto> sysIndicatorList, String endTime, String lastBeginTime, String lastEndTime) {
        // 近15日多个管路流量的日平均流量
        List<String> sensorList = Arrays.asList(analysisConfig.getWaterDisaster().get("water_inflow_sensors").split(","));
        String before15Day = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(DateUtils.getNowDate(), -16));
        String begin15Time = before15Day + " 00:00:00";
        Float baseValue = productionService.getDayAvgFlow(sensorList, begin15Time, endTime, mybatisMineCodeConfig.getCode());
        Float waterInflow = productionService.getDayAvgFlow(sensorList, lastBeginTime, lastEndTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto waterInflowDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.WaterDisasterConstant.WATER) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.WaterDisasterConstant.DAILY_CUMULATIVE_DISCAHRGE)).findFirst().orElse(null);
        if (waterInflowDto != null) {
            if (waterInflow != null && waterInflow > 0) {
                waterInflowDto.setIndicatorValue(waterInflow + "_" + baseValue);
                float waterPercent = ((waterInflow - baseValue) / baseValue) * 100;
                waterInflowDto.setIndicatorReason(String.format("日累计排水量 %s m³, 累计排水量变化幅度为 %s%s", waterInflow, waterPercent, "%"));
            } else {
                waterInflowDto.setIndicatorValue("0.0");
                waterInflowDto.setIndicatorReason("无风速传感器位置及数值数据");
            }
        }
    }

    private void mineGasJudge(List<SysIndicatorDto> sysIndicatorList, Date currentTime) {
        List<SysMineIndicatorModel> gasJudgeModelList = Lists.newArrayList();
        //staff score
        float educationalLevel = 0.0f;
        float averageAge = 0.0f;
        float personalTraining = 0.0f;
        float personalTrainingScore = 0.0f;
        float overcrowding = 0.0f;
        float proManagementPersonal = 0.0f;
        float abnormalLeadership = 0.0f;

        //educational
        SysIndicatorDto educationalDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.EDUCATIONAL_LEVEL)).findFirst().orElse(null);
        if (educationalDto != null) {
            String educationPercent = educationalDto.getIndicatorValue();
            float educationLevelScore = GasRuleUtil.getEducationLevelScores(Float.parseFloat(educationPercent));
            educationalLevel = educationLevelScore * educationalDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), educationalDto.getCreateTime(), currentTime, educationalDto.getIndicatorFirstLevelCode(), educationalDto.getIndicatorSecondLevelCode(), educationalDto.getIndicatorThirdLevelCode(), educationalLevel, String.valueOf(educationLevelScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        // average_age
        SysIndicatorDto averageAgeDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.AVERAGE_AGE)).findFirst().orElse(null);
        if (averageAgeDto != null) {
            String avgAge = averageAgeDto.getIndicatorValue();
            float averageAgeScores = GasRuleUtil.getAverageScores(Float.parseFloat(avgAge));
            averageAge = averageAgeScores * averageAgeDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), averageAgeDto.getCreateTime(), currentTime, averageAgeDto.getIndicatorFirstLevelCode(), averageAgeDto.getIndicatorSecondLevelCode(), averageAgeDto.getIndicatorThirdLevelCode(), averageAge, String.valueOf(averageAgeScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //personal_training
        SysIndicatorDto personalTrainingDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.PERSONAL_TRAINING)).findFirst().orElse(null);
        if (personalTrainingDto != null) {
            String personalTrainPercent = personalTrainingDto.getIndicatorValue();
            float staffTrainingScore = GasRuleUtil.getStaffTrainingScores(Float.parseFloat(personalTrainPercent));
            personalTraining = staffTrainingScore * personalTrainingDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), personalTrainingDto.getCreateTime(), currentTime, personalTrainingDto.getIndicatorFirstLevelCode(), personalTrainingDto.getIndicatorSecondLevelCode(), personalTrainingDto.getIndicatorThirdLevelCode(), personalTraining, String.valueOf(staffTrainingScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        // qualified_rate_safety
        SysIndicatorDto qualifiedRateSafetyDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.QUALIFIED_RATE_OF_SAFETY_TRAINING_TIME)).findFirst().orElse(null);
        if (qualifiedRateSafetyDto != null) {
            String qualifiedRateSafety = qualifiedRateSafetyDto.getIndicatorValue();
            float qualifiedRateSafetyScore = GasRuleUtil.getSafetyTrainingPercent(Float.parseFloat(qualifiedRateSafety));
            personalTrainingScore = qualifiedRateSafetyScore * qualifiedRateSafetyDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), qualifiedRateSafetyDto.getCreateTime(), currentTime, qualifiedRateSafetyDto.getIndicatorFirstLevelCode(), qualifiedRateSafetyDto.getIndicatorSecondLevelCode(), qualifiedRateSafetyDto.getIndicatorThirdLevelCode(), personalTrainingScore, String.valueOf(qualifiedRateSafetyScore), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //overcrowding
        SysIndicatorDto overcrowdingDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.OVERCROWDING)).findFirst().orElse(null);
        if (overcrowdingDto != null) {
            String overcrowdingValue = overcrowdingDto.getIndicatorValue();
            float overcrowdingScores = GasRuleUtil.getOverStaffScores(Integer.parseInt(overcrowdingValue));
            overcrowding = overcrowdingScores * overcrowdingDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), overcrowdingDto.getCreateTime(), currentTime, overcrowdingDto.getIndicatorFirstLevelCode(), overcrowdingDto.getIndicatorSecondLevelCode(), overcrowdingDto.getIndicatorThirdLevelCode(), overcrowding, String.valueOf(overcrowdingScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //pro_management_personal
        SysIndicatorDto proManagementPersonalDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.PROFESSIONAL_ALLOCATION_MANAGEMENT_PERSONNEL)).findFirst().orElse(null);
        if (proManagementPersonalDto != null) {
            String proManagementPersonalValue = proManagementPersonalDto.getIndicatorValue();
            float proManagementPersonalScores = GasRuleUtil.getManagementEquipScores(Integer.parseInt(proManagementPersonalValue));
            proManagementPersonal = proManagementPersonalScores * proManagementPersonalDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), proManagementPersonalDto.getCreateTime(), currentTime, proManagementPersonalDto.getIndicatorFirstLevelCode(), proManagementPersonalDto.getIndicatorSecondLevelCode(), proManagementPersonalDto.getIndicatorThirdLevelCode(), proManagementPersonal, String.valueOf(proManagementPersonalScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //abnormal_leadership
        SysIndicatorDto abnormalLeadershipDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.ABNORMAL_LEADERSHIP)).findFirst().orElse(null);
        if (abnormalLeadershipDto != null) {
            String abnormalLeadershipValue = abnormalLeadershipDto.getIndicatorValue();
            float abnormalLeadershipScores = GasRuleUtil.getLeaderDutyScores(Integer.parseInt(abnormalLeadershipValue));
            abnormalLeadership = abnormalLeadershipScores * abnormalLeadershipDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), abnormalLeadershipDto.getCreateTime(), currentTime, abnormalLeadershipDto.getIndicatorFirstLevelCode(), abnormalLeadershipDto.getIndicatorSecondLevelCode(), abnormalLeadershipDto.getIndicatorThirdLevelCode(), abnormalLeadership, String.valueOf(abnormalLeadershipScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        // final_gas_staff
        SysIndicatorDto finalGasStaffDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_STAFF) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (finalGasStaffDto != null) {
            float gasStaff = educationalLevel + averageAge + personalTraining + personalTrainingScore + overcrowding + proManagementPersonal + abnormalLeadership;
            float finalGasStaff = gasStaff * finalGasStaffDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), finalGasStaffDto.getCreateTime(), currentTime, finalGasStaffDto.getIndicatorFirstLevelCode(), finalGasStaffDto.getIndicatorSecondLevelCode(), finalGasStaffDto.getIndicatorThirdLevelCode(), finalGasStaff, String.valueOf(gasStaff), ""));
        }


        //equipment score
        float miningMechanlevel = 0.0f;
        float systemOperationInterruption = 0.0f;
        float antiExplosionFacilities = 0.0f;
        float explosionLossRate = 0.0f;
        float localFanStartStop = 0.0f;
        float windGasPowerLockout = 0.0f;
        float sensorCalibration = 0.0f;
        //mining_mechan_level
        SysIndicatorDto miningMechanLevelDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.MINING_MECHANIZATION_LEVEL)).findFirst().orElse(null);
        if (miningMechanLevelDto != null) {
            String miningMechanLevelValue = miningMechanLevelDto.getIndicatorValue();
            float miningMechanLevelScores = GasRuleUtil.getMiningMechanicalsLevelScores(Float.parseFloat(miningMechanLevelValue));
            miningMechanlevel = miningMechanLevelScores * miningMechanLevelDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), miningMechanLevelDto.getCreateTime(), currentTime, miningMechanLevelDto.getIndicatorFirstLevelCode(), miningMechanLevelDto.getIndicatorSecondLevelCode(), miningMechanLevelDto.getIndicatorThirdLevelCode(), miningMechanlevel, String.valueOf(miningMechanLevelScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //system_operation_interruption
        SysIndicatorDto systemOperationInterruptionDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SYSTEM_OPERATION_INTERRUPTION)).findFirst().orElse(null);
        if (systemOperationInterruptionDto != null) {
            String systemOperationInterruptionValue = systemOperationInterruptionDto.getIndicatorValue();
            float systemOperationInterruptionScores = GasRuleUtil.getSystemInterruptionScores(Integer.parseInt(systemOperationInterruptionValue));
            systemOperationInterruption = systemOperationInterruptionScores * systemOperationInterruptionDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), systemOperationInterruptionDto.getCreateTime(), currentTime, systemOperationInterruptionDto.getIndicatorFirstLevelCode(), systemOperationInterruptionDto.getIndicatorSecondLevelCode(), systemOperationInterruptionDto.getIndicatorThirdLevelCode(), systemOperationInterruption, String.valueOf(systemOperationInterruptionScores), systemOperationInterruptionDto.getIndicatorReason()));
        }
        //anti_explosion_facilities
        SysIndicatorDto antiExplosionFacilitiesDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.ANTI_EXPLOSION_FACILITIES)).findFirst().orElse(null);
        if (antiExplosionFacilitiesDto != null) {
            String antiExplosionFacilitiesValue = antiExplosionFacilitiesDto.getIndicatorValue();
            float antiExplosionFacilitiesScores = GasRuleUtil.getExplosionProofFacilities(Float.parseFloat(antiExplosionFacilitiesValue));
            antiExplosionFacilities = antiExplosionFacilitiesScores * antiExplosionFacilitiesDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), antiExplosionFacilitiesDto.getCreateTime(), currentTime, antiExplosionFacilitiesDto.getIndicatorFirstLevelCode(), antiExplosionFacilitiesDto.getIndicatorSecondLevelCode(), antiExplosionFacilitiesDto.getIndicatorThirdLevelCode(), antiExplosionFacilities, String.valueOf(antiExplosionFacilitiesScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //explosion_loss_rate
        SysIndicatorDto explosionLossRateDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.EXPLOSION_LOSS_RATE_ELECTRICAL_EQUIPMENT)).findFirst().orElse(null);
        if (explosionLossRateDto != null) {
            String explosionLossRateValue = explosionLossRateDto.getIndicatorValue();
            float explosionLossRateScores = GasRuleUtil.getElectricalExplosionPercentScores(Float.parseFloat(explosionLossRateValue));
            explosionLossRate = explosionLossRateScores * explosionLossRateDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), explosionLossRateDto.getCreateTime(), currentTime, explosionLossRateDto.getIndicatorFirstLevelCode(), explosionLossRateDto.getIndicatorSecondLevelCode(), explosionLossRateDto.getIndicatorThirdLevelCode(), explosionLossRate, String.valueOf(explosionLossRateScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //local_fan_start_stop
        SysIndicatorDto localFanStartStopDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.LOCAL_FAN_START_STOP)).findFirst().orElse(null);
        if (localFanStartStopDto != null) {
            String localFanStartStopValue = localFanStartStopDto.getIndicatorValue();
            float localFanStartStopScores = GasRuleUtil.getLocalVentilatorOnAndOff(Integer.parseInt(localFanStartStopValue));
            localFanStartStop = localFanStartStopScores * localFanStartStopDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), localFanStartStopDto.getCreateTime(), currentTime, localFanStartStopDto.getIndicatorFirstLevelCode(), localFanStartStopDto.getIndicatorSecondLevelCode(), localFanStartStopDto.getIndicatorThirdLevelCode(), localFanStartStop, String.valueOf(localFanStartStopScores), localFanStartStopDto.getIndicatorReason()));
        }
        //wind_gas_power_lockout
        SysIndicatorDto windAndGasPowerLockoutDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.WIND_AND_GAS_POWER_LOCKOUT)).findFirst().orElse(null);
        if (windAndGasPowerLockoutDto != null) {
            String windAndGasPowerLockoutValue = windAndGasPowerLockoutDto.getIndicatorValue();
            float windAndGasPowerLockoutScores = GasRuleUtil.getWindGasElectricalLock(Integer.parseInt(windAndGasPowerLockoutValue));
            windGasPowerLockout = windAndGasPowerLockoutScores * windAndGasPowerLockoutDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), windAndGasPowerLockoutDto.getCreateTime(), currentTime, windAndGasPowerLockoutDto.getIndicatorFirstLevelCode(), windAndGasPowerLockoutDto.getIndicatorSecondLevelCode(), windAndGasPowerLockoutDto.getIndicatorThirdLevelCode(), windGasPowerLockout, String.valueOf(windAndGasPowerLockoutScores), windAndGasPowerLockoutDto.getIndicatorReason()));
        }
        //sensor_calibration
        SysIndicatorDto sensorCalibrationDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SENSOR_CALIBRATION_ON_TIME)).findFirst().orElse(null);
        if (sensorCalibrationDto != null) {
            String sensorCalibrationValue = sensorCalibrationDto.getIndicatorValue();
            float sensorCalibrationScores = GasRuleUtil.getSensorCalibrationStatus(Integer.parseInt(sensorCalibrationValue));
            sensorCalibration = sensorCalibrationScores * sensorCalibrationDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), sensorCalibrationDto.getCreateTime(), currentTime, sensorCalibrationDto.getIndicatorFirstLevelCode(), sensorCalibrationDto.getIndicatorSecondLevelCode(), sensorCalibrationDto.getIndicatorThirdLevelCode(), sensorCalibration, String.valueOf(sensorCalibrationScores), sensorCalibrationDto.getIndicatorReason()));
        }
        //final_gas_equipment
        SysIndicatorDto finalGasEquipmentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_EQUIPMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (finalGasEquipmentDto != null) {
            float gasEquipment = miningMechanlevel + systemOperationInterruption + antiExplosionFacilities + explosionLossRate + localFanStartStop + windGasPowerLockout + sensorCalibration;
            if (gasEquipment > 100) {
                gasEquipment = 100;
            }
            float finalGasEquipment = gasEquipment * finalGasEquipmentDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), finalGasEquipmentDto.getCreateTime(), currentTime, finalGasEquipmentDto.getIndicatorFirstLevelCode(), finalGasEquipmentDto.getIndicatorSecondLevelCode(), finalGasEquipmentDto.getIndicatorThirdLevelCode(), finalGasEquipment, String.valueOf(gasEquipment), ""));
        }

        //enviorment score
        float gasGeoConditions = 0.0f;
        float gasConcentration = 0.0f;
        float oxygenConcentration = 0.0f;
        float tunnelWindSpeed = 0.0f;
        float coalSeamPermeability = 0.0f;
        float relativeSeamEmission = 0.0f;
        float coalSeamDip = 0.0f;
        float coalSeamThickeness = 0.0f;
        float coalSeamBuriedDepth = 0.0f;
        float firmnessF = 0.0f;
        float gasPressure = 0.0f;
        float gasContent = 0.0f;
        float stableRoofFloor = 0.0f;
        float mineGasGrade = 0.0f;
        //gas_geo_conditions
        SysIndicatorDto gasGeoConditionsDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_GEOLOGICAL_CONDITIONS)).findFirst().orElse(null);
        if (gasGeoConditionsDto != null) {
            String gasGeoConditionsValue = gasGeoConditionsDto.getIndicatorValue();
            float gasGeoConditionsScores = GasRuleUtil.getGasGeologicalConditions(Integer.parseInt(gasGeoConditionsValue));
            gasGeoConditions = gasGeoConditionsScores * gasGeoConditionsDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasGeoConditionsDto.getCreateTime(), currentTime, gasGeoConditionsDto.getIndicatorFirstLevelCode(), gasGeoConditionsDto.getIndicatorSecondLevelCode(), gasGeoConditionsDto.getIndicatorThirdLevelCode(), gasGeoConditions, String.valueOf(gasGeoConditionsScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        // gas_concentration
        SysIndicatorDto gasConcentrationDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_CONCENTRATION)).findFirst().orElse(null);
        if (gasConcentrationDto != null) {
            String gasConcentrationValue = gasConcentrationDto.getIndicatorValue();
            float gasConcentrationScores = GasRuleUtil.getGasConcentration(Float.parseFloat(gasConcentrationValue));
            gasConcentration = gasConcentrationScores * gasConcentrationDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasConcentrationDto.getCreateTime(), currentTime, gasConcentrationDto.getIndicatorFirstLevelCode(), gasConcentrationDto.getIndicatorSecondLevelCode(), gasConcentrationDto.getIndicatorThirdLevelCode(), gasConcentration, String.valueOf(gasConcentrationScores), gasConcentrationDto.getIndicatorReason()));
        }
        //oxygen_concentration
        SysIndicatorDto oxygenConcentrationDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.OXYGEN_CONCENTRATION)).findFirst().orElse(null);
        if (oxygenConcentrationDto != null) {
            String oxygenConcentrationValue = oxygenConcentrationDto.getIndicatorValue();
            float oxygenConcentrationScores = GasRuleUtil.getOxygenConcentration(Float.parseFloat(oxygenConcentrationValue));
            oxygenConcentration = oxygenConcentrationScores * oxygenConcentrationDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), oxygenConcentrationDto.getCreateTime(), currentTime, oxygenConcentrationDto.getIndicatorFirstLevelCode(), oxygenConcentrationDto.getIndicatorSecondLevelCode(), oxygenConcentrationDto.getIndicatorThirdLevelCode(), oxygenConcentration, String.valueOf(oxygenConcentrationScores), oxygenConcentrationDto.getIndicatorReason()));
        }
        //tunnel_wind_speed
        SysIndicatorDto tunnelWindSpeedDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.TUNNEL_WIND_SPEED)).findFirst().orElse(null);
        if (tunnelWindSpeedDto != null) {
            String tunnelWindSpeedValue = tunnelWindSpeedDto.getIndicatorValue();
            float tunnelWindSpeedScores = GasRuleUtil.getRoadwayWindSpeed(Float.parseFloat(tunnelWindSpeedValue));
            tunnelWindSpeed = tunnelWindSpeedScores * tunnelWindSpeedDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), tunnelWindSpeedDto.getCreateTime(), currentTime, tunnelWindSpeedDto.getIndicatorFirstLevelCode(), tunnelWindSpeedDto.getIndicatorSecondLevelCode(), tunnelWindSpeedDto.getIndicatorThirdLevelCode(), tunnelWindSpeed, String.valueOf(tunnelWindSpeedScores), tunnelWindSpeedDto.getIndicatorReason()));
        }
        //coal_seam_permeability
        SysIndicatorDto coalSeamPermeabilityDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.COAL_SEAM_PERMEABILITY)).findFirst().orElse(null);
        if (coalSeamPermeabilityDto != null) {
            String coalSeamPermeabilityValue = coalSeamPermeabilityDto.getIndicatorValue();
            float coalSeamPermeabilityScores = GasRuleUtil.getCoalSeamPermeability(Float.parseFloat(coalSeamPermeabilityValue));
            coalSeamPermeability = coalSeamPermeabilityScores * coalSeamPermeabilityDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalSeamPermeabilityDto.getCreateTime(), currentTime, coalSeamPermeabilityDto.getIndicatorFirstLevelCode(), coalSeamPermeabilityDto.getIndicatorSecondLevelCode(), coalSeamPermeabilityDto.getIndicatorThirdLevelCode(), coalSeamPermeability, String.valueOf(coalSeamPermeabilityScores), coalSeamPermeabilityDto.getIndicatorReason()));
        }
        //relative_seam_emission
        SysIndicatorDto relativeSeamEmissionDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.RELATIVE_GAS_EMISSION)).findFirst().orElse(null);
        if (relativeSeamEmissionDto != null) {
            String relativeSeamEmissionValue = relativeSeamEmissionDto.getIndicatorValue();
            float relativeSeamEmissionScores = GasRuleUtil.getGasRelativeOutflowScores(Integer.parseInt(relativeSeamEmissionValue));
            relativeSeamEmission = relativeSeamEmissionScores * relativeSeamEmissionDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), relativeSeamEmissionDto.getCreateTime(), currentTime, relativeSeamEmissionDto.getIndicatorFirstLevelCode(), relativeSeamEmissionDto.getIndicatorSecondLevelCode(), relativeSeamEmissionDto.getIndicatorThirdLevelCode(), relativeSeamEmission, String.valueOf(relativeSeamEmissionScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //coal_seam_dip
        SysIndicatorDto coalSeamDipDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.COAL_SEAM_DIP)).findFirst().orElse(null);
        if (coalSeamDipDto != null) {
            String coalSeamDipValue = coalSeamDipDto.getIndicatorValue();
            float coalSeamDipScores = GasRuleUtil.getCoalSeamAngleScores(Float.parseFloat(coalSeamDipValue));
            coalSeamDip = coalSeamDipScores * coalSeamDipDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalSeamDipDto.getCreateTime(), currentTime, coalSeamDipDto.getIndicatorFirstLevelCode(), coalSeamDipDto.getIndicatorSecondLevelCode(), coalSeamDipDto.getIndicatorThirdLevelCode(), coalSeamDip, String.valueOf(coalSeamDipScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //coal_seam_thickeness
        SysIndicatorDto coalSeamThickenessDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.COAL_SEAM_THICKNESS_VARIATION_COEFFICIENT)).findFirst().orElse(null);
        if (coalSeamThickenessDto != null) {
            String coalSeamThickenessValue = coalSeamThickenessDto.getIndicatorValue();
            float coalSeamThickenessScores = GasRuleUtil.getCoalSeamThicknessVariationCofficientScores(Float.parseFloat(coalSeamThickenessValue));
            coalSeamThickeness = coalSeamThickenessScores * coalSeamThickenessDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalSeamThickenessDto.getCreateTime(), currentTime, coalSeamThickenessDto.getIndicatorFirstLevelCode(), coalSeamThickenessDto.getIndicatorSecondLevelCode(), coalSeamThickenessDto.getIndicatorThirdLevelCode(), coalSeamThickeness, String.valueOf(coalSeamThickenessScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //coal_seam_buried_depth
        SysIndicatorDto coalSeamBuriedDepthDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.COAL_SEAM_BURIED_DEPTH)).findFirst().orElse(null);
        if (coalSeamBuriedDepthDto != null) {
            String coalSeamBuriedDepthValue = coalSeamBuriedDepthDto.getIndicatorValue();
            float coalSeamBuriedDepthScores = GasRuleUtil.getCoalSeamDepthScores(Float.parseFloat(coalSeamBuriedDepthValue));
            coalSeamBuriedDepth = coalSeamBuriedDepthScores * coalSeamBuriedDepthDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), coalSeamBuriedDepthDto.getCreateTime(), currentTime, coalSeamBuriedDepthDto.getIndicatorFirstLevelCode(), coalSeamBuriedDepthDto.getIndicatorSecondLevelCode(), coalSeamBuriedDepthDto.getIndicatorThirdLevelCode(), coalSeamBuriedDepth, String.valueOf(coalSeamBuriedDepthScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //firmness_f
        SysIndicatorDto firmnessFDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.FIRMNESS_COEFFICIENT_COAL_F)).findFirst().orElse(null);
        if (firmnessFDto != null) {
            String firmnessFValue = firmnessFDto.getIndicatorValue();
            float firmnessFScores = GasRuleUtil.getCoalSolidityCoefficientScores(Float.parseFloat(firmnessFValue));
            firmnessF = firmnessFScores * firmnessFDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), firmnessFDto.getCreateTime(), currentTime, firmnessFDto.getIndicatorFirstLevelCode(), firmnessFDto.getIndicatorSecondLevelCode(), firmnessFDto.getIndicatorThirdLevelCode(), firmnessF, String.valueOf(firmnessFScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //gas_pressure
        SysIndicatorDto gasPressureDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_PRESSURE)).findFirst().orElse(null);
        if (gasPressureDto != null) {
            String gasPressureValue = gasPressureDto.getIndicatorValue();
            float gasPressureScores = GasRuleUtil.getGasPressureScores(Float.parseFloat(gasPressureValue));
            gasPressure = gasPressureScores * gasPressureDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasPressureDto.getCreateTime(), currentTime, gasPressureDto.getIndicatorFirstLevelCode(), gasPressureDto.getIndicatorSecondLevelCode(), gasPressureDto.getIndicatorThirdLevelCode(), gasPressure, String.valueOf(gasPressureScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //gas_content
        SysIndicatorDto gasContentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_CONTENT)).findFirst().orElse(null);
        if (gasContentDto != null) {
            String gasContentValue = gasContentDto.getIndicatorValue();
            float gasContentScores = GasRuleUtil.getGasContentScores(Float.parseFloat(gasContentValue));
            gasContent = gasContentScores * gasContentDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasContentDto.getCreateTime(), currentTime, gasContentDto.getIndicatorFirstLevelCode(), gasContentDto.getIndicatorSecondLevelCode(), gasContentDto.getIndicatorThirdLevelCode(), gasContent, String.valueOf(gasContentScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //stable_roof_floor
        SysIndicatorDto stableRoofFloorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.STABLE_ROOF_FLOOR)).findFirst().orElse(null);
        if (stableRoofFloorDto != null) {
            String stableRoofFloorValue = stableRoofFloorDto.getIndicatorValue();
            float stableRoofFloorScores = GasRuleUtil.getRoofAndFloorStabilityScores(Float.parseFloat(stableRoofFloorValue));
            stableRoofFloor = stableRoofFloorScores * stableRoofFloorDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), stableRoofFloorDto.getCreateTime(), currentTime, stableRoofFloorDto.getIndicatorFirstLevelCode(), stableRoofFloorDto.getIndicatorSecondLevelCode(), stableRoofFloorDto.getIndicatorThirdLevelCode(), stableRoofFloor, String.valueOf(stableRoofFloorScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //mine_gas_grade
        SysIndicatorDto mineGasGradeDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.MINE_GAS_GRADE)).findFirst().orElse(null);
        if (mineGasGradeDto != null) {
            String mineGasGradeValue = mineGasGradeDto.getIndicatorValue();
            float mineGasGradeScores = GasRuleUtil.getMineGasLevelScores(Integer.parseInt(mineGasGradeValue));
            mineGasGrade = mineGasGradeScores * mineGasGradeDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), mineGasGradeDto.getCreateTime(), currentTime, mineGasGradeDto.getIndicatorFirstLevelCode(), mineGasGradeDto.getIndicatorSecondLevelCode(), mineGasGradeDto.getIndicatorThirdLevelCode(), mineGasGrade, String.valueOf(mineGasGradeScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //final_gas_enviorment
        SysIndicatorDto finalGasEnviormentDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_ENVIRONMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (finalGasEnviormentDto != null) {
            float gasEnviorment = gasGeoConditions + gasConcentration + oxygenConcentration + tunnelWindSpeed + coalSeamPermeability + relativeSeamEmission + coalSeamDip + coalSeamThickeness + coalSeamBuriedDepth + firmnessF + gasPressure + gasContent + stableRoofFloor + mineGasGrade;
            float finalGasEnviorment = gasEnviorment * finalGasEnviormentDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), finalGasEnviormentDto.getCreateTime(), currentTime, finalGasEnviormentDto.getIndicatorFirstLevelCode(), finalGasEnviormentDto.getIndicatorSecondLevelCode(), finalGasEnviormentDto.getIndicatorThirdLevelCode(), finalGasEnviorment, String.valueOf(gasEnviorment), ""));
        }

        //management scores
        float emergencyManagementMeasures = 0.0f;
        float safetyInvestmentRate = 0.0f;
        float safetyCultureConstruction = 0.0f;
        float safetySupervisionMechanism = 0.0f;
        float gasAccidentsCount = 0.0f;
        float gasOverlimitCount = 0.0f;
        float gasOverlimitUndoneCount = 0.0f;
        float mineSafetyLevel = 0.0f;
        //emergency_management_measures
        SysIndicatorDto emergencyManagementMeasuresDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.EMERGENCY_MANAGEMENT_MEASURES)).findFirst().orElse(null);
        if (emergencyManagementMeasuresDto != null) {
            String emergencyManagementMeasuresValue = emergencyManagementMeasuresDto.getIndicatorValue();
            float emergencyManagementMeasuresScores = GasRuleUtil.getEmergencyManagementScores(Integer.parseInt(emergencyManagementMeasuresValue));
            emergencyManagementMeasures = emergencyManagementMeasuresScores * emergencyManagementMeasuresDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), emergencyManagementMeasuresDto.getCreateTime(), currentTime, emergencyManagementMeasuresDto.getIndicatorFirstLevelCode(), emergencyManagementMeasuresDto.getIndicatorSecondLevelCode(), emergencyManagementMeasuresDto.getIndicatorThirdLevelCode(), emergencyManagementMeasures, String.valueOf(emergencyManagementMeasuresScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //safety_investment_rate
        SysIndicatorDto safetyInvestmentRateDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SAFETY_INVESTMENT_FULFILLMENT_RATE)).findFirst().orElse(null);
        if (safetyInvestmentRateDto != null) {
            String safetyInvestmentRateValue = safetyInvestmentRateDto.getIndicatorValue();
            float safetyInvestmentRateScores = GasRuleUtil.getInvestmentOvercomePercentScores(Float.parseFloat(safetyInvestmentRateValue));
            safetyInvestmentRate = safetyInvestmentRateScores * safetyInvestmentRateDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), safetyInvestmentRateDto.getCreateTime(), currentTime, safetyInvestmentRateDto.getIndicatorFirstLevelCode(), safetyInvestmentRateDto.getIndicatorSecondLevelCode(), safetyInvestmentRateDto.getIndicatorThirdLevelCode(), safetyInvestmentRate, String.valueOf(safetyInvestmentRateScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //safety_culture_construction
        SysIndicatorDto safetyCultureConstructionDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SAFETY_CULTURE_CONSTRUCTION)).findFirst().orElse(null);
        if (safetyCultureConstructionDto != null) {
            String safetyCultureConstructionValue = safetyCultureConstructionDto.getIndicatorValue();
            float safetyCultureConstructionScores = GasRuleUtil.getSafetyCultureScores(Integer.parseInt(safetyCultureConstructionValue));
            safetyCultureConstruction = safetyCultureConstructionScores * safetyCultureConstructionDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), safetyCultureConstructionDto.getCreateTime(), currentTime, safetyCultureConstructionDto.getIndicatorFirstLevelCode(), safetyCultureConstructionDto.getIndicatorSecondLevelCode(), safetyCultureConstructionDto.getIndicatorThirdLevelCode(), safetyCultureConstruction, String.valueOf(safetyCultureConstructionScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //safety_supervision_mechanism
        SysIndicatorDto safetySupervisionMechanismDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SAFETY_SUPERVISION_MECHANISM)).findFirst().orElse(null);
        if (safetySupervisionMechanismDto != null) {
            String safetySupervisionMechanismValue = safetySupervisionMechanismDto.getIndicatorValue();
            float safetySupervisionMechanismScores = GasRuleUtil.getSafetySupervisedMechanismScores(Integer.parseInt(safetySupervisionMechanismValue));
            safetySupervisionMechanism = safetySupervisionMechanismScores * safetySupervisionMechanismDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), safetySupervisionMechanismDto.getCreateTime(), currentTime, safetySupervisionMechanismDto.getIndicatorFirstLevelCode(), safetySupervisionMechanismDto.getIndicatorSecondLevelCode(), safetySupervisionMechanismDto.getIndicatorThirdLevelCode(), safetySupervisionMechanism, String.valueOf(safetySupervisionMechanismScores), AnalysisConstant.DisasterMessage.EXPERT_MESSAGE));
        }
        //gas_accidents_count
        SysIndicatorDto gasAccidentsCountDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_ACCIDENTS_COUNT)).findFirst().orElse(null);
        if (gasAccidentsCountDto != null) {
            String gasAccidentsCountValue = gasAccidentsCountDto.getIndicatorValue();
            float gasAccidentsCountScores = GasRuleUtil.getGasAccidentCountScores(Integer.parseInt(gasAccidentsCountValue));
            gasAccidentsCount = gasAccidentsCountScores * gasAccidentsCountDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasAccidentsCountDto.getCreateTime(), currentTime, gasAccidentsCountDto.getIndicatorFirstLevelCode(), gasAccidentsCountDto.getIndicatorSecondLevelCode(), gasAccidentsCountDto.getIndicatorThirdLevelCode(), gasAccidentsCount, String.valueOf(gasAccidentsCountScores), gasAccidentsCountDto.getIndicatorReason()));
        }
        //gas_overlimit_count
        SysIndicatorDto gasOverlimitCountDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_OVERLIMIT_COUNT)).findFirst().orElse(null);
        if (gasOverlimitCountDto != null) {
            String gasOverlimitCountValue = gasOverlimitCountDto.getIndicatorValue();
            float gasOverlimitCountScores = GasRuleUtil.getGasOverlimitCountScores(Integer.parseInt(gasOverlimitCountValue));
            gasOverlimitCount = gasOverlimitCountScores * gasOverlimitCountDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasOverlimitCountDto.getCreateTime(), currentTime, gasOverlimitCountDto.getIndicatorFirstLevelCode(), gasOverlimitCountDto.getIndicatorSecondLevelCode(), gasOverlimitCountDto.getIndicatorThirdLevelCode(), gasOverlimitCount, String.valueOf(gasOverlimitCountScores), gasOverlimitCountDto.getIndicatorReason()));
        }
        //gas_overlimit_undone_count
        SysIndicatorDto gasOverlimitUndoneCountDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_OVERLIMIT_UNDONE_COUNT)).findFirst().orElse(null);
        if (gasOverlimitUndoneCountDto != null) {
            String gasOverlimitUndoneCountValue = gasOverlimitUndoneCountDto.getIndicatorValue();
            float gasOverlimitUndoneCountScores = GasRuleUtil.getGasOverlimitUndoneCountScores(Integer.parseInt(gasOverlimitUndoneCountValue));
            gasOverlimitUndoneCount = gasOverlimitUndoneCountScores * gasOverlimitUndoneCountDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), gasOverlimitUndoneCountDto.getCreateTime(), currentTime, gasOverlimitUndoneCountDto.getIndicatorFirstLevelCode(), gasOverlimitUndoneCountDto.getIndicatorSecondLevelCode(), gasOverlimitUndoneCountDto.getIndicatorThirdLevelCode(), gasOverlimitUndoneCount, String.valueOf(gasOverlimitUndoneCountScores), gasOverlimitUndoneCountDto.getIndicatorReason()));
        }
        //mine_safety_level
        SysIndicatorDto mineSafetyLevelDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.MINE_SAFETY_PRODUCTION_LEVEL)).findFirst().orElse(null);
        if (mineSafetyLevelDto != null) {
            String mineSafetyLevelValue = mineSafetyLevelDto.getIndicatorValue();
            float mineSafetyLevelScores = GasRuleUtil.getMineSafetyLevelScores(Integer.parseInt(mineSafetyLevelValue));
            mineSafetyLevel = mineSafetyLevelScores * mineSafetyLevelDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), mineSafetyLevelDto.getCreateTime(), currentTime, mineSafetyLevelDto.getIndicatorFirstLevelCode(), mineSafetyLevelDto.getIndicatorSecondLevelCode(), mineSafetyLevelDto.getIndicatorThirdLevelCode(), mineSafetyLevel, String.valueOf(mineSafetyLevelScores), mineSafetyLevelDto.getIndicatorReason()));
        }
        //final_gas_management
        SysIndicatorDto finalGasManagementDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorSecondLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_MANAGEMENT) && StringUtils.isBlank(s.getIndicatorThirdLevelCode())).findFirst().orElse(null);
        if (finalGasManagementDto != null) {
            float gasManagement = emergencyManagementMeasures + safetyInvestmentRate + safetyCultureConstruction + gasAccidentsCount + gasOverlimitCount + gasOverlimitUndoneCount + mineSafetyLevel + safetySupervisionMechanism;
            float finalGasManagement = gasManagement * finalGasManagementDto.getIndicatorWeightValue();
            gasJudgeModelList.add(new SysMineIndicatorModel(mybatisMineCodeConfig.getCode(), finalGasManagementDto.getCreateTime(), currentTime, finalGasManagementDto.getIndicatorFirstLevelCode(), finalGasManagementDto.getIndicatorSecondLevelCode(), finalGasManagementDto.getIndicatorThirdLevelCode(), finalGasManagement, String.valueOf(gasManagement), ""));
        }
        if (CollectionUtils.isNotEmpty(gasJudgeModelList)) {
            minerService.batchInsertWeightScores(gasJudgeModelList);
        }
    }


    private void processGasDisaster(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        //超员情况
        setOvercrowdingStatus(beginTime, endTime, sysIndicatorList);
        //井下领导带班空岗现象
        setLeaderOnDuty(beginTime, endTime, sysIndicatorList);
        //传感器断线、基站断电、基站不同中断现象
        setSystemOperationInterruption(beginTime, endTime, sysIndicatorList);
        //局部通风机停机现象
        setLocalVentilatorStatus(beginTime, endTime, sysIndicatorList);
        //连续15天内发现传感器标校记录
        setSenorCabliration(sysIndicatorList);
        //甲烷传感器浓度
        setCoalfaceGasMaxValue(beginTime, endTime, sysIndicatorList);
        //氧气传感器
        setCoalfaceOxygenMaxValue(beginTime, endTime, sysIndicatorList);
        //风速传感器
        setCoalfaceWindspeedMaxValue(beginTime, endTime, sysIndicatorList);
        //瓦斯浓度监测超限次数
        setCoalfaceGasAlarmCount(beginTime, endTime, sysIndicatorList);
        //瓦斯浓度超限未处理次数
        setCoalfaceGasAlarmUndoneCount(beginTime, endTime, sysIndicatorList);
        //风电瓦斯闭锁
        setWindAndGasPowerLockout(sysIndicatorList);
    }

    private void setWindAndGasPowerLockout(List<SysIndicatorDto> sysIndicatorList) {
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.WIND_AND_GAS_POWER_LOCKOUT)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(String.valueOf(1));
            sysIndicatorDto.setIndicatorReason("");
        }
    }

    private void setCoalfaceGasAlarmUndoneCount(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        int gasAlarmUndoneCount = safetyService.getGasAlarmUndoneCount(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_OVERLIMIT_UNDONE_COUNT)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(String.valueOf(gasAlarmUndoneCount));
            sysIndicatorDto.setIndicatorReason(gasAlarmUndoneCount > 0 ? String.format("瓦斯浓度超限未处理次数为 %s次", gasAlarmUndoneCount) : "瓦斯浓度超限未处理次数为0次");
        }
    }

    private void setCoalfaceGasAlarmCount(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        int gasAlarmCount = safetyService.getGasAlarmCount(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_OVERLIMIT_COUNT)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(String.valueOf(gasAlarmCount));
            sysIndicatorDto.setIndicatorReason(gasAlarmCount > 0 ? String.format("瓦斯浓度监测超限次数为 %s次", gasAlarmCount) : "瓦斯浓度监测超限次数为0次");
        }
    }

    private void setCoalfaceWindspeedMaxValue(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        List<SensorMonitorDto> sensorMonitorList = safetyService.getCoalfaceWindspeed(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.TUNNEL_WIND_SPEED)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            if (CollectionUtils.isNotEmpty(sensorMonitorList)) {
                sensorMonitorList.sort(Comparator.comparing(SensorMonitorDto::getPointMaxValue).reversed());
                SensorMonitorDto sensorMonitorDto = sensorMonitorList.get(0);
                sysIndicatorDto.setIndicatorValue(String.valueOf(sensorMonitorDto.getPointMaxValue()));
                sysIndicatorDto.setIndicatorReason(String.format("传感器编号%s, %s 位置风速传感器，传感器数值为%s", sensorMonitorDto.getPointCode(), sensorMonitorDto.getPointLocation(), sensorMonitorDto.getPointMaxValue()));
            } else {
                sysIndicatorDto.setIndicatorValue("0");
                sysIndicatorDto.setIndicatorReason("无风速传感器位置及数值数据");
            }
        }
    }

    private void setCoalfaceOxygenMaxValue(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        List<SensorMonitorDto> sensorMonitorList = safetyService.getCoalfaceOxygen(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.OXYGEN_CONCENTRATION)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            if (CollectionUtils.isNotEmpty(sensorMonitorList)) {
                sensorMonitorList.sort(Comparator.comparing(SensorMonitorDto::getPointMaxValue).reversed());
                SensorMonitorDto sensorMonitorDto = sensorMonitorList.get(0);
                sysIndicatorDto.setIndicatorValue(String.valueOf(sensorMonitorDto.getPointMaxValue()));
                sysIndicatorDto.setIndicatorReason(String.format("传感器%s, %s 位置氧气传感器，传感器数值为%s", sensorMonitorDto.getPointCode(), sensorMonitorDto.getPointLocation(), sensorMonitorDto.getPointMaxValue()));
            } else {
                sysIndicatorDto.setIndicatorValue("0");
                sysIndicatorDto.setIndicatorReason("无氧气传感器位置及数值数据");
            }
        }
    }

    private void setCoalfaceGasMaxValue(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        List<SensorMonitorDto> sensorMonitorList = safetyService.getHisCoalfaceGas(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.GAS_CONCENTRATION)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            if (CollectionUtils.isNotEmpty(sensorMonitorList)) {
                sensorMonitorList.sort(Comparator.comparing(SensorMonitorDto::getPointMaxValue).reversed());
                SensorMonitorDto sensorMonitorDto = sensorMonitorList.get(0);
                int gasScores = GasRuleUtil.getGasConcentration(sensorMonitorDto.getPointMaxValue());
                sysIndicatorDto.setIndicatorValue(String.valueOf(sensorMonitorDto.getPointMaxValue()));
                if (gasScores == 0) {
                    sysIndicatorDto.setIndicatorReason(String.format("传感器编号%s, %s 位置甲烷传感器浓度为 %s, 超出《煤矿安全规程》中规定阈值", sensorMonitorDto.getPointCode(), sensorMonitorDto.getPointLocation(), sensorMonitorDto.getPointMaxValue()));
                } else {
                    sysIndicatorDto.setIndicatorReason(String.format("传感器编号%s, %s 位置甲烷传感器浓度为 %s, 未超出《煤矿安全规程》中规定阈值", sensorMonitorDto.getPointCode(), sensorMonitorDto.getPointLocation(), sensorMonitorDto.getPointMaxValue()));
                }
            } else {
                sysIndicatorDto.setIndicatorValue("0");
                sysIndicatorDto.setIndicatorReason("无瓦斯传感器位置及数值数据");
            }
        }
    }


    private void setSenorCabliration(List<SysIndicatorDto> sysIndicatorList) {
        String before15Day = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(DateUtils.getNowDate(), -15));
        String begin15Time = before15Day + " 00:00:00";
        String end15Time = before15Day + " 23:59:59";
        List<String> pointCodes = safetyService.getSenorCablirationAlarm(begin15Time, end15Time, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SENSOR_CALIBRATION_ON_TIME)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(!pointCodes.isEmpty() ? "1" : "0");
            sysIndicatorDto.setIndicatorReason(!pointCodes.isEmpty() ? "连续15天内发现传感器标校记录" : "连续15天内未发现传感器标校记录");
        }
    }

    private void setLocalVentilatorStatus(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        int count = safetyService.getVentilatorOffineStatus(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.LOCAL_FAN_START_STOP)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(count > 0 ? "0" : "1");
            sysIndicatorDto.setIndicatorReason(count > 0 ? "出现局部通风机停机现象" : "未出现局部通风机停机现象");
        }
    }

    private void setSystemOperationInterruption(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        List<HisSensorAlarmDto> hisSensorAlarmDtoList = safetyService.getHisSensorAlarm(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.SYSTEM_OPERATION_INTERRUPTION)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            if (CollectionUtils.isNotEmpty(hisSensorAlarmDtoList)) {
                Map<String, List<HisSensorAlarmDto>> collect = hisSensorAlarmDtoList.stream().collect(Collectors.groupingBy(HisSensorAlarmDto::getOutlierType));
                List<String> tempList = new ArrayList<>();
                if (collect.containsKey("004")) {
                    tempList.add("传感器断线");
                }
                if (collect.containsKey("005")) {
                    tempList.add("传感器断线");
                }
                if (collect.containsKey("006")) {
                    tempList.add("基站不通");
                }
                String messages = String.join(",", tempList);
                sysIndicatorDto.setIndicatorValue("0");
                sysIndicatorDto.setIndicatorReason(String.format("系统出现 %s 中断现象", messages));
            } else {
                sysIndicatorDto.setIndicatorValue("1");
                sysIndicatorDto.setIndicatorReason("系统未出现传感器断线、基站断电、基站不同中断现象");
            }
        }
    }

    private void setLeaderOnDuty(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        int count = safetyService.getLeaderOnDuty(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.ABNORMAL_LEADERSHIP)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(count > 0 ? "1" : "0");
            sysIndicatorDto.setIndicatorReason(count > 0 ? "本矿出现井下领导带班空岗现象" : "本矿未出现井下领导带班空岗现象");
        }
    }

    private void setOvercrowdingStatus(String beginTime, String endTime, List<SysIndicatorDto> sysIndicatorList) {
        int count = safetyService.getOvercrowdData(beginTime, endTime, mybatisMineCodeConfig.getCode());
        SysIndicatorDto sysIndicatorDto = sysIndicatorList.stream().filter(s -> StringUtils.equals(s.getIndicatorFirstLevelCode(), AnalysisConstant.GasDisasterConstant.GAS) && StringUtils.equals(s.getIndicatorThirdLevelCode(), AnalysisConstant.GasDisasterConstant.OVERCROWDING)).findFirst().orElse(null);
        if (sysIndicatorDto != null) {
            sysIndicatorDto.setIndicatorValue(count > 0 ? "1" : "0");
            sysIndicatorDto.setIndicatorReason(count > 0 ? "本矿出现超员情况" : "本矿未出现超员情况");
        }
    }


    private AnalysisScoreDto getInternalFireScores(String beginTime, String endTime) {
        AnalysisScoreDto analysisScoreDto = null;
        SensorMonitorVo svo = new SensorMonitorVo();
        svo.setMineCode(mybatisMineCodeConfig.getCode());
        svo.setBeginTime(beginTime);
        svo.setEndTime(endTime);
        svo.setSensorType("0003");
        svo.setPointLocation("上隅角");
        List<SensorMonitorDto> monitorDtoList = safetyService.getHisSensorMonitor(svo);
        if (CollectionUtils.isNotEmpty(monitorDtoList)) {
            monitorDtoList.sort(Comparator.comparing((SensorMonitorDto monitorDto) -> monitorDto.getPointCode() + "~" + monitorDto.getPointLocation()).reversed());
            SensorMonitorDto sensorMonitorDto = monitorDtoList.get(0);
            int alarmLevel = getInternalFireTemperatureLevel(sensorMonitorDto.getPointMaxValue());
            float scores = getInternalFireRiskLevel(alarmLevel);
            analysisScoreDto = new AnalysisScoreDto(sensorMonitorDto.getPointCode(), sensorMonitorDto.getPointLocation(), sensorMonitorDto.getPointMaxValue(), alarmLevel, Objects.requireNonNull(AlarmEnum.getAlarmEnum(alarmLevel)).getDesc(), scores);
        }
        return analysisScoreDto;
    }

    private List<Float> getCoConfig() {
        Map<String, Float> securityMonitor = analysisConfig.getSecurityMonitor();
        return Arrays.asList(securityMonitor.get("co_value_1"), securityMonitor.get("co_value_2"), securityMonitor.get("co_value_3"), securityMonitor.get("co_value_4"), securityMonitor.get("co_duration_1"), securityMonitor.get("co_duration_2"), securityMonitor.get("co_duration_3"));
    }

    private List<Float> getSmokeConfig() {
        Map<String, Float> securityMonitor = analysisConfig.getSecurityMonitor();
        return Arrays.asList(securityMonitor.get("smoke_duration_1"), securityMonitor.get("smoke_duration_2"), securityMonitor.get("smoke_duration_3"));
    }

    private List<Float> getTemperatureConfig() {
        Map<String, Float> securityMonitor = analysisConfig.getSecurityMonitor();
        return Arrays.asList(securityMonitor.get("temperature_value_1"), securityMonitor.get("temperature_value_2"), securityMonitor.get("temperature_value_3"), securityMonitor.get("temperature_duration_1"), securityMonitor.get("temperature_duration_2"), securityMonitor.get("temperature_duration_3"));
    }

    private int getInternalFireTemperatureLevel(Float temperature) {
        int result = 0;
        if (temperature >= 0 && temperature < 40) {
            result = 1;
        } else if (temperature >= 40 && temperature < 60) {
            result = 2;
        } else if (temperature >= 60 && temperature < 80) {
            result = 3;
        } else if (temperature >= 80 && temperature < 130) {
            result = 4;
        } else if (temperature >= 130 && temperature < 160) {
            result = 5;
        } else if (temperature >= 160 && temperature < 180) {
            result = 6;
        } else if (temperature >= 180) {
            result = 7;
        }
        return result;
    }

    public float getInternalFireRiskLevel(int internalFireRiskLevel) {
        float result;

        if (internalFireRiskLevel == 1 || internalFireRiskLevel == 0) {
            result = 100.0f;
        } else if (internalFireRiskLevel == 2) {
            result = getRandomFloat(85.0f, 92.0f);
        } else if (internalFireRiskLevel == 3) {
            result = getRandomFloat(80.0f, 85.0f);
        } else if (internalFireRiskLevel == 4) {
            result = getRandomFloat(75.0f, 80.0f);
        } else if (internalFireRiskLevel == 5) {
            result = getRandomFloat(68.0f, 75.0f);
        } else if (internalFireRiskLevel == 6) {
            result = getRandomFloat(60.0f, 68.0f);
        } else {
            result = getRandomFloat(0.0f, 60.0f);
        }

        // 保留两位小数
        return Math.round(result * 100.0f) / 100.0f;
    }

    /**
     * 生成指定范围内的随机浮点数
     */
    private float getRandomFloat(float min, float max) {
        return min + random.nextFloat() * (max - min);
    }

}
